private TcpServer( EndPoint endPoint, IThreadPool threadPool, Func <TcpPeer> peerFactory, TcpServerSettings settings) { try { EndPoint = endPoint; Settings = settings ?? TcpServerSettings.Default; var acceptArgs = new SocketAsyncEventArgs(); acceptArgs.Completed += OnAcceptCompleted; _connections = new ConcurrentDictionary <long, TcpServerConnection>(); _actorSystem = new ActorSystem(EndPoint.ToString(), threadPool); _actorSystem.RegisterFactoryOf(peerFactory); _tcpServerConnectionNumber = 0; _socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _socket.Bind(endPoint); _socket.Listen(Settings.Backlog); _receiveBufferPool = new FixedArrayPool <byte>(Settings.ReceiveBufferSize, 10000); StartAccept(_socket, acceptArgs); } catch { if (_socket != null) { _socket.Close(); _socket.Dispose(); } throw; } }
internal static TcpServerConnection Accept( TcpServer server, long number, Socket socket, ActorRef <TcpPeer> peer, FixedArrayPool <byte> buffers) { return(new TcpServerConnection(server, number, socket, peer, buffers)); }
private TcpServerConnection( TcpServer server, long number, Socket socket, ActorRef <TcpPeer> peer, FixedArrayPool <byte> buffers) { _server = server; _number = number; _socket = socket; _peer = peer; _buffers = buffers; _connected = true; _receive = new SocketAsyncEventArgs(); _receive.Completed += OnReceiveCompleted; StartReceive(socket, _receive); }