Skip to content

Commit 405a191

Browse files
committed
Bug fix.
1 parent 5639a60 commit 405a191

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

Quick.Protocol.SerialPort/QpSerialPortClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public QpSerialPortClient(QpSerialPortClientOptions options) : base(options)
2121
protected override async Task<Stream> InnerConnectAsync()
2222
{
2323
if (LogUtils.LogConnection)
24-
Console.WriteLine($"Opening SerialPort[{options.PortName}]...");
24+
LogUtils.Log($"Opening SerialPort[{options.PortName}]...");
2525
serialPort = new System.IO.Ports.SerialPort(options.PortName,
2626
options.BaudRate,
2727
options.Parity,
2828
options.DataBits,
2929
options.StopBits);
3030
await Task.Run(() => serialPort.Open());
3131
if (LogUtils.LogConnection)
32-
Console.WriteLine($"SerialPort[{options.PortName}] open success.");
32+
LogUtils.Log($"SerialPort[{options.PortName}] open success.");
3333
serialPort.WriteTimeout = options.TransportTimeout;
3434
serialPort.WriteLine(QpConsts.QuickProtocolNameAndVersion);
3535
return serialPort.BaseStream;

Quick.Protocol.SerialPort/QpSerialPortServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public override void Start()
2323
{
2424
this.ChannelDisconnected += QpSerialPortServer_ChannelDisconnected;
2525
if (LogUtils.LogConnection)
26-
Console.WriteLine($"Opening SerialPort[{options.PortName}]...");
26+
LogUtils.Log($"Opening SerialPort[{options.PortName}]...");
2727
serialPort = new System.IO.Ports.SerialPort(options.PortName,
2828
options.BaudRate,
2929
options.Parity,
3030
options.DataBits,
3131
options.StopBits);
3232
serialPort.Open();
3333
if (LogUtils.LogConnection)
34-
Console.WriteLine($"SerialPort[{options.PortName}] open success.");
34+
LogUtils.Log($"SerialPort[{options.PortName}] open success.");
3535
isAccepted = false;
3636
base.Start();
3737
}

Quick.Protocol.Tcp/QpTcpServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ protected override Task InnerAcceptAsync(CancellationToken token)
4545
{
4646
var remoteEndPointStr = "TCP:" + tcpClient.Client.RemoteEndPoint.ToString();
4747
if (LogUtils.LogConnection)
48-
Console.WriteLine("[Connection]{0} connected.", remoteEndPointStr);
48+
LogUtils.Log("[Connection]{0} connected.", remoteEndPointStr);
4949
OnNewChannelConnected(tcpClient.GetStream(), remoteEndPointStr, token);
5050
}
5151
catch (Exception ex)
5252
{
5353
if (LogUtils.LogConnection)
54-
Console.WriteLine("[Connection]Init&Start Channel error,reason:{0}", ex.ToString());
54+
LogUtils.Log("[Connection]Init&Start Channel error,reason:{0}", ex.ToString());
5555
try { tcpClient.Close(); }
5656
catch { }
5757
}

Quick.Protocol.WebSocket.Server.AspNetCore/QpWebSocketServer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Task OnNewConnection(System.Net.WebSockets.WebSocket webSocket, Connectio
5454
return Task.Delay(-1, cts.Token).ContinueWith(t =>
5555
{
5656
if (LogUtils.LogConnection)
57-
Console.WriteLine("[Connection]{0} disconnected.", connectionInfoStr);
57+
LogUtils.Log("[Connection]{0} disconnected.", connectionInfoStr);
5858
});
5959
}
6060

@@ -85,13 +85,13 @@ protected override async Task InnerAcceptAsync(CancellationToken token)
8585
try
8686
{
8787
if (LogUtils.LogConnection)
88-
Console.WriteLine("[Connection]{0} connected.", context.ConnectionInfo);
88+
LogUtils.Log("[Connection]{0} connected.", context.ConnectionInfo);
8989
OnNewChannelConnected(new WebSocketServerStream(context.WebSocket, context.Cts), context.ConnectionInfo, token);
9090
}
9191
catch (Exception ex)
9292
{
9393
if (LogUtils.LogConnection)
94-
Console.WriteLine("[Connection]Init&Start Channel error,reason:{0}", ex.ToString());
94+
LogUtils.Log("[Connection]Init&Start Channel error,reason:{0}", ex.ToString());
9595
try { await context.WebSocket.CloseAsync(System.Net.WebSockets.WebSocketCloseStatus.InternalServerError, ex.Message, CancellationToken.None); }
9696
catch { }
9797
}

Quick.Protocol/QpServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected void OnNewChannelConnected(Stream stream, string channelName, Cancella
7070
channel.AuchenticateTimeout += (sender, e) =>
7171
{
7272
if (LogUtils.LogConnection)
73-
LogUtils.Log("[Connection]{0} auchenticate timeout.", channelName);
73+
LogUtils.Log("[Connection]{0} Auchenticate timeout.", channelName);
7474
ChannelAuchenticateTimeout?.Invoke(this, channel);
7575
};
7676

Quick.Protocol/QpServerChannel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ public QpServerChannel(QpServer server, Stream stream, string channelName, Cance
5959
if (options.AuthenticateTimeout>0)
6060
Task.Delay(options.AuthenticateTimeout, cts.Token).ContinueWith(t =>
6161
{
62-
if (t.IsCanceled)
62+
//如果已经取消或者已经连接
63+
if (t.IsCanceled
64+
|| IsConnected)
6365
return;
66+
if (LogUtils.LogConnection)
67+
LogUtils.Log("[Connection]{0} Authenticate timeout.", channelName);
68+
6469
if (stream!=null)
6570
{
6671
try
@@ -102,7 +107,7 @@ private Commands.Authenticate.Response authenticate(QpChannel handler, Commands.
102107
{
103108
Stop();
104109
});
105-
throw new CommandException(1, "认证失败!");
110+
throw new CommandException(1, "Authenticate failed.");
106111
}
107112
IsConnected=true;
108113
Auchenticated?.Invoke(this, EventArgs.Empty);

Test/WebSocket/WebApplication1/Core/QpTestContext.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ public class QpTestContext
1313

1414
public QpTestContext(IApplicationBuilder app)
1515
{
16+
//Quick.Protocol.Utils.LogUtils.SetConsoleLogHandler();
17+
Quick.Protocol.Utils.LogUtils.LogPackage=true;
18+
Quick.Protocol.Utils.LogUtils.LogContent=true;
1619
Quick.Protocol.Utils.LogUtils.LogConnection = true;
17-
Quick.Protocol.Utils.LogUtils.LogHeartbeat = false;
20+
Quick.Protocol.Utils.LogUtils.LogHeartbeat = true;
1821

1922
app.UseQuickProtocol(new Quick.Protocol.WebSocket.Server.AspNetCore.QpWebSocketServerOptions()
2023
{

0 commit comments

Comments
 (0)