完善ProcessAccept
This commit is contained in:
parent
4211f40b6c
commit
4330dd92a5
@ -321,30 +321,34 @@ namespace HaoYueNet.ServerNetwork
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Interlocked.Increment(ref m_clientCount);
|
Interlocked.Increment(ref m_clientCount);
|
||||||
// Get the socket for the accepted client connection and put it into the
|
//确保监听结束时,有连接才抛给数据接收
|
||||||
//ReadEventArg object user token
|
if (e.AcceptSocket.RemoteEndPoint != null)
|
||||||
SocketAsyncEventArgs readEventArgs = m_Receivepool.Pop();
|
|
||||||
//TODO readEventArgs.UserToken这里的 UserToken 有可能是空
|
|
||||||
AsyncUserToken userToken;
|
|
||||||
if (readEventArgs.UserToken == null)
|
|
||||||
readEventArgs.UserToken = new AsyncUserToken();
|
|
||||||
|
|
||||||
userToken = (AsyncUserToken)readEventArgs.UserToken;
|
|
||||||
userToken.Socket = e.AcceptSocket;
|
|
||||||
userToken.ConnectTime = DateTime.Now;
|
|
||||||
userToken.Remote = e.AcceptSocket.RemoteEndPoint;
|
|
||||||
userToken.IPAddress = ((IPEndPoint)(e.AcceptSocket.RemoteEndPoint)).Address;
|
|
||||||
|
|
||||||
|
|
||||||
userToken.RevIndex = MaxRevIndexNum;
|
|
||||||
userToken.SendIndex = MaxSendIndexNum;
|
|
||||||
|
|
||||||
AddUserToken(userToken);
|
|
||||||
|
|
||||||
OnClientNumberChange?.Invoke(1, userToken);
|
|
||||||
if (!e.AcceptSocket.ReceiveAsync(readEventArgs))
|
|
||||||
{
|
{
|
||||||
ProcessReceive(readEventArgs);
|
// Get the socket for the accepted client connection and put it into the
|
||||||
|
//ReadEventArg object user token
|
||||||
|
SocketAsyncEventArgs readEventArgs = m_Receivepool.Pop();
|
||||||
|
//TODO readEventArgs.UserToken这里的 UserToken 有可能是空
|
||||||
|
AsyncUserToken userToken;
|
||||||
|
if (readEventArgs.UserToken == null)
|
||||||
|
readEventArgs.UserToken = new AsyncUserToken();
|
||||||
|
|
||||||
|
userToken = (AsyncUserToken)readEventArgs.UserToken;
|
||||||
|
userToken.Socket = e.AcceptSocket;
|
||||||
|
userToken.ConnectTime = DateTime.Now;
|
||||||
|
userToken.Remote = e.AcceptSocket.RemoteEndPoint;
|
||||||
|
userToken.IPAddress = ((IPEndPoint)(e.AcceptSocket.RemoteEndPoint)).Address;
|
||||||
|
|
||||||
|
|
||||||
|
userToken.RevIndex = MaxRevIndexNum;
|
||||||
|
userToken.SendIndex = MaxSendIndexNum;
|
||||||
|
|
||||||
|
AddUserToken(userToken);
|
||||||
|
|
||||||
|
OnClientNumberChange?.Invoke(1, userToken);
|
||||||
|
if (!e.AcceptSocket.ReceiveAsync(readEventArgs))
|
||||||
|
{
|
||||||
|
ProcessReceive(readEventArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception me)
|
catch (Exception me)
|
||||||
|
@ -321,30 +321,35 @@ namespace HaoYueNet.ServerNetwork
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Interlocked.Increment(ref m_clientCount);
|
Interlocked.Increment(ref m_clientCount);
|
||||||
// Get the socket for the accepted client connection and put it into the
|
|
||||||
//ReadEventArg object user token
|
|
||||||
SocketAsyncEventArgs readEventArgs = m_Receivepool.Pop();
|
|
||||||
//TODO readEventArgs.UserToken这里的 UserToken 有可能是空
|
|
||||||
AsyncUserToken userToken;
|
|
||||||
if (readEventArgs.UserToken == null)
|
|
||||||
readEventArgs.UserToken = new AsyncUserToken();
|
|
||||||
|
|
||||||
userToken = (AsyncUserToken)readEventArgs.UserToken;
|
//确保监听结束时,有连接才抛给数据接收
|
||||||
userToken.Socket = e.AcceptSocket;
|
if (e.AcceptSocket.RemoteEndPoint != null)
|
||||||
userToken.ConnectTime = DateTime.Now;
|
|
||||||
userToken.Remote = e.AcceptSocket.RemoteEndPoint;
|
|
||||||
userToken.IPAddress = ((IPEndPoint)(e.AcceptSocket.RemoteEndPoint)).Address;
|
|
||||||
|
|
||||||
|
|
||||||
userToken.RevIndex = MaxRevIndexNum;
|
|
||||||
userToken.SendIndex = MaxSendIndexNum;
|
|
||||||
|
|
||||||
AddUserToken(userToken);
|
|
||||||
|
|
||||||
OnClientNumberChange?.Invoke(1, userToken);
|
|
||||||
if (!e.AcceptSocket.ReceiveAsync(readEventArgs))
|
|
||||||
{
|
{
|
||||||
ProcessReceive(readEventArgs);
|
// Get the socket for the accepted client connection and put it into the
|
||||||
|
//ReadEventArg object user token
|
||||||
|
SocketAsyncEventArgs readEventArgs = m_Receivepool.Pop();
|
||||||
|
//TODO readEventArgs.UserToken这里的 UserToken 有可能是空
|
||||||
|
AsyncUserToken userToken;
|
||||||
|
if (readEventArgs.UserToken == null)
|
||||||
|
readEventArgs.UserToken = new AsyncUserToken();
|
||||||
|
|
||||||
|
userToken = (AsyncUserToken)readEventArgs.UserToken;
|
||||||
|
userToken.Socket = e.AcceptSocket;
|
||||||
|
userToken.ConnectTime = DateTime.Now;
|
||||||
|
userToken.Remote = e.AcceptSocket.RemoteEndPoint;
|
||||||
|
userToken.IPAddress = ((IPEndPoint)(e.AcceptSocket.RemoteEndPoint)).Address;
|
||||||
|
|
||||||
|
|
||||||
|
userToken.RevIndex = MaxRevIndexNum;
|
||||||
|
userToken.SendIndex = MaxSendIndexNum;
|
||||||
|
|
||||||
|
AddUserToken(userToken);
|
||||||
|
|
||||||
|
OnClientNumberChange?.Invoke(1, userToken);
|
||||||
|
if (!e.AcceptSocket.ReceiveAsync(readEventArgs))
|
||||||
|
{
|
||||||
|
ProcessReceive(readEventArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception me)
|
catch (Exception me)
|
||||||
|
Loading…
Reference in New Issue
Block a user