HttpServer.HttpContext.Start C# (CSharp) Method

Start() private method

Start content.
A socket operation failed. Reading from stream failed.
private Start ( ) : void
return void
		internal void Start()
		{
			Stream = CreateStream(Socket);
			Stream.BeginRead(_buffer, 0, _buffer.Length, OnReceive, null);
		}

Usage Example

Exemplo n.º 1
0
        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);
            }
        }