本文整理汇总了C#中System.Net.Sockets.Socket.CloseEx方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.CloseEx方法的具体用法?C# Socket.CloseEx怎么用?C# Socket.CloseEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.Socket
的用法示例。
在下文中一共展示了Socket.CloseEx方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSessionAccepted
protected virtual void OnSessionAccepted(Listener listener, Socket socket)
{
if (Stopped.IsTrue())
return;
// TODO 여기서 동접 체크?
SocketAsyncEventArgs recvSAEA;
if (!m_RecvSAEAPool.TryPop(out recvSAEA))
{
Task.Run(() => { socket.CloseEx(); });
Logger.Error(string.Format("Max connection number {0} was reached!", m_ServerConfig.MaxConnectionNumber));
return;
}
SocketAsyncEventArgs sendSAEA;
if (!m_SendSAEAPool.TryPop(out sendSAEA))
{
Task.Run(() => { socket.CloseEx(); });
Logger.Error(string.Format("Max connection number {0} was reached!", m_ServerConfig.MaxConnectionNumber));
return;
}
Session session = CreateSession(socket, recvSAEA, sendSAEA);
if (session == null)
{
recvSAEA.UserToken = null;
sendSAEA.UserToken = null;
m_RecvSAEAPool.Push(recvSAEA);
m_SendSAEAPool.Push(sendSAEA);
Task.Run(() => { socket.CloseEx(); });
return;
}
session.Connected += OnSessionConnected;
session.Disconnected += OnSessionDisconnected;
session.Received += OnSessionReceived;
session.Error += OnSessionError;
long sessionID = GenerateSessionID();
session.SetSessionID(sessionID);
m_Sessions.TryAdd(sessionID, session);
session.OnConnected();
// TODO
session.StartReceive();
Logger.Debug(string.Format("OnSessionAccepted:{0}", session.m_ID));
}