mirror of
https://github.com/ThingsGateway/ThingsGateway.git
synced 2026-10-28 11:47:24 +08:00
update touchsocket
This commit is contained in:
@@ -123,25 +123,6 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Close(string msg)
|
||||
{
|
||||
this.OnClosed(true, msg);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool SendClose(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.SendString(0, msg);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 建立对点
|
||||
@@ -1051,7 +1032,7 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
}
|
||||
}
|
||||
|
||||
#region 重写
|
||||
#region 断开
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
@@ -1070,7 +1051,25 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
this.WaitHandlePool.SafeDispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public void Close(string msg)
|
||||
{
|
||||
this.OnClosed(true, msg);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool SendClose(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.SendString(0, msg);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endregion 重写
|
||||
|
||||
#region 协议同步发送
|
||||
|
||||
+8
-5
@@ -39,10 +39,10 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
#endregion 字段
|
||||
|
||||
/// <inheritdoc cref="IDmtpActor.Id"/>
|
||||
public string Id => this.DmtpActor.Id;
|
||||
public string Id => this.m_dmtpActor.Id;
|
||||
|
||||
/// <inheritdoc cref="IDmtpActor.IsHandshaked"/>
|
||||
public bool IsHandshaked => this.DmtpActor != null && this.DmtpActor.IsHandshaked;
|
||||
public bool IsHandshaked => this.m_dmtpActor != null && this.m_dmtpActor.IsHandshaked;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IDmtpActor DmtpActor { get => this.m_dmtpActor; }
|
||||
@@ -219,7 +219,10 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
this.m_dmtpActor?.SafeDispose();
|
||||
if (this.IsHandshaked)
|
||||
{
|
||||
this.m_dmtpActor?.SafeDispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
@@ -230,7 +233,7 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
/// <returns></returns>
|
||||
public override void Close(string msg = "")
|
||||
{
|
||||
if (this.m_dmtpActor != null)
|
||||
if (this.IsHandshaked)
|
||||
{
|
||||
this.m_dmtpActor.SendClose(msg);
|
||||
this.m_dmtpActor.Close(msg);
|
||||
@@ -303,7 +306,7 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
Routing = this.OnDmtpActorRouting,
|
||||
Handshaking = this.OnDmtpActorHandshaking,
|
||||
Handshaked = this.OnDmtpActorHandshaked,
|
||||
Closed = OnDmtpActorClose,
|
||||
Closed = this.OnDmtpActorClose,
|
||||
CreatedChannel = this.OnDmtpActorCreateChannel,
|
||||
Logger = this.Logger,
|
||||
Client = this,
|
||||
|
||||
+11
-5
@@ -42,7 +42,7 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
public IDmtpActor DmtpActor { get => this.m_dmtpActor; }
|
||||
|
||||
/// <inheritdoc cref="IDmtpActor.Id"/>
|
||||
public string Id => this.DmtpActor.Id;
|
||||
public string Id => this.m_dmtpActor.Id;
|
||||
|
||||
#region 字段
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
#endregion 字段
|
||||
|
||||
/// <inheritdoc cref="IDmtpActor.IsHandshaked"/>
|
||||
public bool IsHandshaked => this.DmtpActor != null && this.DmtpActor.IsHandshaked;
|
||||
public bool IsHandshaked => this.m_dmtpActor != null && this.m_dmtpActor.IsHandshaked;
|
||||
|
||||
#region 断开
|
||||
|
||||
@@ -65,15 +65,21 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
/// <returns></returns>
|
||||
public override void Close(string msg = "")
|
||||
{
|
||||
this.m_dmtpActor?.SendClose(msg);
|
||||
this.m_dmtpActor?.Close(msg);
|
||||
if (this.IsHandshaked)
|
||||
{
|
||||
this.m_dmtpActor?.SendClose(msg);
|
||||
this.m_dmtpActor?.Close(msg);
|
||||
}
|
||||
base.Close(msg);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
this.m_dmtpActor?.SafeDispose();
|
||||
if (this.IsHandshaked)
|
||||
{
|
||||
this.m_dmtpActor?.SafeDispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
||||
+13
-4
@@ -161,22 +161,31 @@ namespace ThingsGateway.Foundation.Dmtp
|
||||
/// <returns></returns>
|
||||
public override void Close(string msg = "")
|
||||
{
|
||||
this.m_dmtpActor?.SendClose(msg);
|
||||
this.m_dmtpActor?.Close(msg);
|
||||
if (this.IsHandshaked)
|
||||
{
|
||||
this.m_dmtpActor?.SendClose(msg);
|
||||
this.m_dmtpActor?.Close(msg);
|
||||
}
|
||||
base.Close(msg);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
this.m_dmtpActor?.SafeDispose();
|
||||
if (this.IsHandshaked)
|
||||
{
|
||||
this.m_dmtpActor?.SafeDispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task OnDisconnected(DisconnectEventArgs e)
|
||||
{
|
||||
this.m_dmtpActor?.Close(e.Message);
|
||||
if (this.IsHandshaked)
|
||||
{
|
||||
this.m_dmtpActor?.Close(e.Message);
|
||||
}
|
||||
await base.OnDisconnected(e).ConfigureFalseAwait();
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -215,6 +215,17 @@ public class SerialCore : IDisposable, ISender
|
||||
this.m_receiveBufferSize = this.MinBufferSize;
|
||||
this.m_sendBufferSize = this.MinBufferSize;
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断,当不在连接状态时触发异常。
|
||||
/// </summary>
|
||||
/// <exception cref="NotConnectedException"></exception>
|
||||
protected void ThrowIfNotConnected()
|
||||
{
|
||||
if (!this.m_online)
|
||||
{
|
||||
throw new NotConnectedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据。
|
||||
@@ -227,6 +238,7 @@ public class SerialCore : IDisposable, ISender
|
||||
/// <param name="length"></param>
|
||||
public virtual void Send(byte[] buffer, int offset, int length)
|
||||
{
|
||||
this.ThrowIfNotConnected();
|
||||
try
|
||||
{
|
||||
this.m_semaphoreForSend.Wait();
|
||||
@@ -249,6 +261,7 @@ public class SerialCore : IDisposable, ISender
|
||||
/// <exception cref="Exception"></exception>
|
||||
public virtual async Task SendAsync(byte[] buffer, int offset, int length)
|
||||
{
|
||||
this.ThrowIfNotConnected();
|
||||
try
|
||||
{
|
||||
await this.m_semaphoreForSend.WaitAsync();
|
||||
|
||||
+13
-1
@@ -296,7 +296,17 @@ public class TcpCore : SocketAsyncEventArgs, IDisposable, ISender
|
||||
this.m_sendBufferSize = this.MinBufferSize;
|
||||
this.m_online = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断,当不在连接状态时触发异常。
|
||||
/// </summary>
|
||||
/// <exception cref="NotConnectedException"></exception>
|
||||
protected void ThrowIfNotConnected()
|
||||
{
|
||||
if (!this.m_online)
|
||||
{
|
||||
throw new NotConnectedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送数据。
|
||||
/// <para>
|
||||
@@ -308,6 +318,7 @@ public class TcpCore : SocketAsyncEventArgs, IDisposable, ISender
|
||||
/// <param name="length"></param>
|
||||
public virtual void Send(byte[] buffer, int offset, int length)
|
||||
{
|
||||
this.ThrowIfNotConnected();
|
||||
if (this.UseSsl)
|
||||
{
|
||||
this.SslStream.Write(buffer, offset, length);
|
||||
@@ -349,6 +360,7 @@ public class TcpCore : SocketAsyncEventArgs, IDisposable, ISender
|
||||
/// <exception cref="Exception"></exception>
|
||||
public virtual async Task SendAsync(byte[] buffer, int offset, int length)
|
||||
{
|
||||
this.ThrowIfNotConnected();
|
||||
#if NET6_0_OR_GREATER
|
||||
if (this.UseSsl)
|
||||
{
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ namespace ThingsGateway.Foundation.Sockets
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public NotConnectedException()
|
||||
public NotConnectedException() : this(TouchSocketResource.NotConnected.GetDescription())
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user