internal void Start() { Stream = CreateStream(Socket); Stream.BeginRead(_buffer, 0, _buffer.Length, OnReceive, null); }
private void OnSocketAccepted(IAsyncResult ar) { HttpFactory.Current = Factory; Socket socket = null; try { socket = _listener.EndAcceptSocket(ar); Interlocked.Decrement(ref _pendingAccepts); if (_shuttingDown && _pendingAccepts == 0) { _shutdownEvent.Set(); } if (!CanAcceptSocket(socket)) { _logger.Debug("Socket was rejected: " + socket.RemoteEndPoint); socket.Disconnect(true); BeginAccept(); return; } } catch (Exception err) { _logger.Warning("Failed to end accept: " + err.Message); BeginAccept(); if (socket != null) { socket.Disconnect(true); } return; } if (!_shuttingDown) { BeginAccept(); } _logger.Trace("Accepted connection from: " + socket.RemoteEndPoint); // Got a new context. try { HttpContext context = CreateContext(socket); HttpContext.Current = context; context.HttpFactory = _factory; context.RequestReceived += OnRequest; context.Disconnected += OnDisconnect; context.ContinueResponseRequested += On100Continue; context.Start(); } catch (Exception err) { _logger.Error("ContextReceived raised an exception: " + err.Message); socket.Disconnect(true); } }