/// <summary> /// A callback that gets invoked after we bind. /// </summary> /// <param name="result"></param> private void AcceptCallback(IAsyncResult result) { if (!IsActive) { return; } Socket remoteSocket = null; try { remoteSocket = Socket.EndAccept(result); SockNetLogger.Log(SockNetLogger.LogLevel.INFO, this, "Accepted connection from: [{0}]", remoteSocket.RemoteEndPoint); } finally { if (ServerSockNetChannelState.Bound.Equals(State)) { Socket.BeginAccept(new AsyncCallback(AcceptCallback), Socket); } else { remoteSocket.Close(); remoteSocket = null; } } if (remoteSocket != null) { RemoteSockNetChannel channel = new RemoteSockNetChannel(this, remoteSocket, BufferPool, modules.Values); remoteChannels[channel.Id] = channel; } }
/// <summary> /// Notifies this server of a disconnected channel. /// </summary> /// <param name="channel"></param> internal void RemoteChannelDisconnected(RemoteSockNetChannel channel) { remoteChannels.Remove(channel.Id); }