/// <summary> /// Accepts the new client connection. /// </summary> /// <param name="asyncResult">Handle of the asynchronous accept operation</param> private void EndAccept(IAsyncResult asyncResult) { var socket = (Socket)asyncResult.AsyncState; Socket clientSocket; try { clientSocket = socket.EndAccept(asyncResult); } catch (ObjectDisposedException) { // Listener socket was closed return; } // Listen for another connections right away socket.BeginAccept(EndAccept, socket); // Disable Nagle algorithm for control channel clientSocket.NoDelay = true; // Enable TCP keepalive for control channel if (keepAliveSettings != null) { clientSocket.IOControl(IOControlCode.KeepAliveValues, keepAliveSettings, null); } // Create logger scope for the connection var loggerScope = new LoggerScope(clientSocket.RemoteEndPoint, logger); loggerScope.WriteInfo(TraceResources.ClientConnected); // Create the server instance to handle all client communications serverFactory .Create(clientSocket, loggerScope) .Run(CancellationToken.None); }
public IServer Create(IHttpRequestDelegate del, IScheduler scheduler) { return(serverFactory.Create(new HttpServerDelegate(del), scheduler)); }