private static async void ProcessAccept(SocketAsyncEventArgs args) { HttpEndPointListener epl = (HttpEndPointListener)args.UserToken; if (epl._closed) { return; } // http://msdn.microsoft.com/en-us/library/system.net.sockets.acceptSocket.acceptasync%28v=vs.110%29.aspx // Under certain conditions ConnectionReset can occur // Need to attept to re-accept var socketError = args.SocketError; var accepted = args.AcceptSocket; epl.Accept(args); if (socketError == SocketError.ConnectionReset) { epl._logger.LogError("SocketError.ConnectionReset reported. Attempting to re-accept."); return; } if (accepted == null) { return; } if (epl._secure && epl._cert == null) { TryClose(accepted); return; } try { var remoteEndPointString = accepted.RemoteEndPoint == null ? string.Empty : accepted.RemoteEndPoint.ToString(); var localEndPointString = accepted.LocalEndPoint == null ? string.Empty : accepted.LocalEndPoint.ToString(); //_logger.LogInformation("HttpEndPointListener Accepting connection from {0} to {1} secure connection requested: {2}", remoteEndPointString, localEndPointString, _secure); HttpConnection conn = new HttpConnection(epl._logger, accepted, epl, epl._secure, epl._cert, epl._cryptoProvider, epl._streamHelper, epl._textEncoding, epl._fileSystem, epl._environment); await conn.Init().ConfigureAwait(false); //_logger.LogDebug("Adding unregistered connection to {0}. Id: {1}", accepted.RemoteEndPoint, connectionId); lock (epl._unregisteredConnections) { epl._unregisteredConnections[conn] = conn; } conn.BeginReadRequest(); } catch (Exception ex) { epl._logger.LogError(ex, "Error in ProcessAccept"); TryClose(accepted); epl.Accept(); return; } }
private async Task ProcessAccept(Socket accepted) { var listener = this; if (listener._secure && listener._cert == null) { accepted.Close(); return; } var remoteEndPointString = accepted.RemoteEndPoint == null ? string.Empty : accepted.RemoteEndPoint.ToString(); var localEndPointString = accepted.LocalEndPoint == null ? string.Empty : accepted.LocalEndPoint.ToString(); //_logger.Info("HttpEndPointListener Accepting connection from {0} to {1} secure connection requested: {2}", remoteEndPointString, localEndPointString, _secure); HttpConnection conn = new HttpConnection(_logger, accepted, listener, _secure, _cert, _cryptoProvider, _memoryStreamFactory, _textEncoding, _fileSystem, _environment); await conn.Init().ConfigureAwait(false); //_logger.Debug("Adding unregistered connection to {0}. Id: {1}", accepted.RemoteEndPoint, connectionId); lock (listener._unregisteredConnections) { listener._unregisteredConnections[conn] = conn; } conn.BeginReadRequest(); }