void OnAccept(SocketAsyncEventArgs asyncArgs) { if (asyncArgs.SocketError != SocketError.Success) { OnAcceptError(asyncArgs); return; } Connection connection; if (ConnectionPool.TryPop(out connection)) { Connections.Add(connection); connection.Socket = asyncArgs.AcceptSocket; Receive(connection); PushMessage(MetaMessagePool.Pop(MessageType.Connected, connection)); } else { //TODO: Error } AcceptAsync(); }
void AcceptDone(IAsyncResult result) { var clientSocket = Socket.EndAccept(result); Connection connection; if (ConnectionPool.TryPop(out connection)) { SlimCommon.Log.Default.Info("[SlimIOCP] Client connected from " + clientSocket.RemoteEndPoint); Connections.Add(connection); connection.Socket = clientSocket; connection.Connected = true; Receive(connection); PushMessage(MetaMessagePool.Pop(MessageType.Connected, connection)); } else { //TODO: Error } Accept(); }
public void Disconnect(Connection connection) { SlimCommon.Log.Default.Info("[SlimIOCP] Disconnected " + connection.RemoteEndPoint); lock (connection) { if (connection.Connected) { connection.Connected = false; Connections.Remove(connection); PushMessage(MetaMessagePool.Pop(MessageType.Disconnected, connection)); ShutdownSocket(connection.Socket); } } }
public void Connect(IPEndPoint endPoint) { Socket = null; InitSocket(endPoint); Socket.Connect(endPoint); IsConnected = true; var connection = new Connection(this); connection.Socket = Socket; Receive(connection); Connections.Add(connection); PushMessage(MetaMessagePool.Pop(MessageType.Connected, connection)); }