Update NetworkManager.TcpNetworkChannel.cs

This commit is contained in:
ALEXTANG
2022-09-02 17:06:28 +08:00
parent b0119b711c
commit 4af929beb6

View File

@@ -33,10 +33,7 @@ namespace TEngine.Runtime
/// </summary> /// </summary>
public override ServiceType ServiceType public override ServiceType ServiceType
{ {
get get { return ServiceType.Tcp; }
{
return ServiceType.Tcp;
}
} }
/// <summary> /// <summary>
@@ -87,7 +84,9 @@ namespace TEngine.Runtime
if (NetworkChannelError != null) if (NetworkChannelError != null)
{ {
SocketException socketException = exception as SocketException; SocketException socketException = exception as SocketException;
NetworkChannelError(this, NetworkErrorCode.ConnectError, socketException != null ? socketException.SocketErrorCode : SocketError.Success, exception.ToString()); NetworkChannelError(this, NetworkErrorCode.ConnectError,
socketException != null ? socketException.SocketErrorCode : SocketError.Success,
exception.ToString());
return; return;
} }
@@ -112,7 +111,9 @@ namespace TEngine.Runtime
if (NetworkChannelError != null) if (NetworkChannelError != null)
{ {
SocketException socketException = exception as SocketException; SocketException socketException = exception as SocketException;
NetworkChannelError(this, NetworkErrorCode.ConnectError, socketException != null ? socketException.SocketErrorCode : SocketError.Success, exception.ToString()); NetworkChannelError(this, NetworkErrorCode.ConnectError,
socketException != null ? socketException.SocketErrorCode : SocketError.Success,
exception.ToString());
return; return;
} }
@@ -149,7 +150,7 @@ namespace TEngine.Runtime
var buffBodyCount = buffer[0]; var buffBodyCount = buffer[0];
var buffTotalCount = m_NetworkChannelHelper.PacketHeaderLength + buffBodyCount; var buffTotalCount = m_NetworkChannelHelper.PacketHeaderLength + buffBodyCount;
m_SendState.Stream.SetLength(buffTotalCount); m_SendState.Stream.SetLength(buffTotalCount);
m_Socket.BeginSend(buffer,0,buffTotalCount, SocketFlags.None, m_SendCallback, m_Socket); m_Socket.BeginSend(buffer, 0, buffTotalCount, SocketFlags.None, m_SendCallback, m_Socket);
} }
catch (Exception exception) catch (Exception exception)
{ {
@@ -157,7 +158,9 @@ namespace TEngine.Runtime
if (NetworkChannelError != null) if (NetworkChannelError != null)
{ {
SocketException socketException = exception as SocketException; SocketException socketException = exception as SocketException;
NetworkChannelError(this, NetworkErrorCode.SendError, socketException != null ? socketException.SocketErrorCode : SocketError.Success, exception.ToString()); NetworkChannelError(this, NetworkErrorCode.SendError,
socketException != null ? socketException.SocketErrorCode : SocketError.Success,
exception.ToString());
return; return;
} }
@@ -184,20 +187,15 @@ namespace TEngine.Runtime
if (NetworkChannelError != null) if (NetworkChannelError != null)
{ {
SocketException socketException = exception as SocketException; SocketException socketException = exception as SocketException;
NetworkChannelError(this, NetworkErrorCode.SendError, socketException != null ? socketException.SocketErrorCode : SocketError.Success, exception.ToString()); NetworkChannelError(this, NetworkErrorCode.SendError,
socketException != null ? socketException.SocketErrorCode : SocketError.Success,
exception.ToString());
return; return;
} }
throw; throw;
} }
// m_SendState.Stream.Position += bytesSent;
// if (m_SendState.Stream.Position < m_SendState.Stream.Length)
// {
// SendAsync();
// return;
// }
m_SentPacketCount++; m_SentPacketCount++;
m_SendState.Reset(); m_SendState.Reset();
} }
@@ -207,7 +205,9 @@ namespace TEngine.Runtime
m_ReceiveState.Stream.SetLength(ReceiveState.DefaultBufferLength); m_ReceiveState.Stream.SetLength(ReceiveState.DefaultBufferLength);
try try
{ {
m_Socket.BeginReceive(m_ReceiveState.Stream.GetBuffer(), (int)m_ReceiveState.Stream.Position, (int)(m_ReceiveState.Stream.Length - m_ReceiveState.Stream.Position), SocketFlags.None, m_ReceiveCallback, m_Socket); m_Socket.BeginReceive(m_ReceiveState.Stream.GetBuffer(), (int)m_ReceiveState.Stream.Position,
(int)(m_ReceiveState.Stream.Length - m_ReceiveState.Stream.Position), SocketFlags.None,
m_ReceiveCallback, m_Socket);
} }
catch (Exception exception) catch (Exception exception)
{ {
@@ -215,7 +215,9 @@ namespace TEngine.Runtime
if (NetworkChannelError != null) if (NetworkChannelError != null)
{ {
SocketException socketException = exception as SocketException; SocketException socketException = exception as SocketException;
NetworkChannelError(this, NetworkErrorCode.ReceiveError, socketException != null ? socketException.SocketErrorCode : SocketError.Success, exception.ToString()); NetworkChannelError(this, NetworkErrorCode.ReceiveError,
socketException != null ? socketException.SocketErrorCode : SocketError.Success,
exception.ToString());
return; return;
} }
@@ -242,7 +244,9 @@ namespace TEngine.Runtime
if (NetworkChannelError != null) if (NetworkChannelError != null)
{ {
SocketException socketException = exception as SocketException; SocketException socketException = exception as SocketException;
NetworkChannelError(this, NetworkErrorCode.ReceiveError, socketException != null ? socketException.SocketErrorCode : SocketError.Success, exception.ToString()); NetworkChannelError(this, NetworkErrorCode.ReceiveError,
socketException != null ? socketException.SocketErrorCode : SocketError.Success,
exception.ToString());
return; return;
} }