AddConnection() private method

private AddConnection ( HttpConnection cnc ) : void
cnc HttpConnection
return void
Example #1
0
        private void registerContext(HttpListener listener)
        {
            if (_lastListener != listener)
            {
                removeConnection();

                if (!listener.AddConnection(this))
                {
                    close();

                    return;
                }

                _lastListener = listener;
            }

            _context.Listener = listener;

            if (!_context.Authenticate())
            {
                return;
            }

            if (!_context.Register())
            {
                return;
            }

            _contextRegistered = true;
        }
Example #2
0
        private static void onRead(IAsyncResult asyncResult)
        {
            //Discarded unreachable code: IL_00cb
            HttpConnection httpConnection = (HttpConnection)asyncResult.AsyncState;

            if (httpConnection._socket == null)
            {
                return;
            }
            lock (httpConnection._sync)
            {
                if (httpConnection._socket == null)
                {
                    return;
                }
                int num = -1;
                try
                {
                    httpConnection._timer.Change(-1, -1);
                    num = httpConnection._stream.EndRead(asyncResult);
                    httpConnection._requestBuffer.Write(httpConnection._buffer, 0, num);
                    if (httpConnection._requestBuffer.Length > 32768)
                    {
                        httpConnection.SendError("Bad request", 400);
                        httpConnection.Close(force: true);
                        return;
                    }
                }
                catch
                {
                    if (httpConnection._requestBuffer != null && httpConnection._requestBuffer.Length > 0)
                    {
                        httpConnection.SendError();
                    }
                    httpConnection.close();
                    return;
                }
                if (num <= 0)
                {
                    httpConnection.close();
                }
                else if (httpConnection.processInput(httpConnection._requestBuffer.GetBuffer()))
                {
                    if (!httpConnection._context.HasError)
                    {
                        httpConnection._context.Request.FinishInitialization();
                    }
                    if (httpConnection._context.HasError)
                    {
                        httpConnection.SendError();
                        httpConnection.Close(force: true);
                        return;
                    }
                    if (!httpConnection._listener.BindContext(httpConnection._context))
                    {
                        httpConnection.SendError("Invalid host", 400);
                        httpConnection.Close(force: true);
                        return;
                    }
                    HttpListener listener = httpConnection._context.Listener;
                    if (httpConnection._lastListener != listener)
                    {
                        httpConnection.removeConnection();
                        listener.AddConnection(httpConnection);
                        httpConnection._lastListener = listener;
                    }
                    httpConnection._contextWasBound = true;
                    listener.RegisterContext(httpConnection._context);
                }
                else
                {
                    httpConnection._stream.BeginRead(httpConnection._buffer, 0, 8192, onRead, httpConnection);
                }
            }
        }
Example #3
0
        private void onReadInternal(IAsyncResult asyncResult)
        {
            this._timer.Change(-1, -1);
            int num = -1;

            try
            {
                num = this._stream.EndRead(asyncResult);
                this._requestBuffer.Write(this._buffer, 0, num);
                if (this._requestBuffer.Length > 32768L)
                {
                    this.SendError();
                    this.Close(true);
                    return;
                }
            }
            catch
            {
                if (this._requestBuffer != null && this._requestBuffer.Length > 0L)
                {
                    this.SendError();
                }
                if (this._socket != null)
                {
                    this.closeSocket();
                    this.unbind();
                }
                return;
            }
            if (num <= 0)
            {
                this.closeSocket();
                this.unbind();
                return;
            }
            if (this.processInput(this._requestBuffer.GetBuffer()))
            {
                if (this._context.HaveError)
                {
                    this.SendError();
                    this.Close(true);
                    return;
                }
                this._context.Request.FinishInitialization();
                if (!this._epListener.BindContext(this._context))
                {
                    this.SendError("Invalid host", 400);
                    this.Close(true);
                    return;
                }
                HttpListener listener = this._context.Listener;
                if (this._lastListener != listener)
                {
                    this.removeConnection();
                    listener.AddConnection(this);
                    this._lastListener = listener;
                }
                this._contextWasBound = true;
                listener.RegisterContext(this._context);
                return;
            }
            else
            {
                this._stream.BeginRead(this._buffer, 0, 8192, new AsyncCallback(HttpConnection.onRead), this);
            }
        }
Example #4
0
        void OnReadInternal(IAsyncResult ares)
        {
            timer.Change(Timeout.Infinite, Timeout.Infinite);
            int nread = -1;

            try
            {
                nread = stream.EndRead(ares);
                ms.Write(buffer, 0, nread);
                if (ms.Length > 32768)
                {
                    SendError("Bad request", 400);
                    Close(true);
                    return;
                }
            }
            catch
            {
                if (ms != null && ms.Length > 0)
                {
                    SendError();
                }
                if (sock != null)
                {
                    CloseSocket();
                    Unbind();
                }
                return;
            }

            if (nread == 0)
            {
                //if (ms.Length > 0)
                //	SendError (); // Why bother?
                CloseSocket();
                Unbind();
                return;
            }

            if (ProcessInput(ms))
            {
                if (!context.HaveError)
                {
                    context.Request.FinishInitialization();
                }

                if (context.HaveError)
                {
                    SendError();
                    Close(true);
                    return;
                }

                if (!epl.BindContext(context))
                {
                    SendError("Invalid host", 400);
                    Close(true);
                    return;
                }
                HttpListener listener = context.Listener;
                if (last_listener != listener)
                {
                    RemoveConnection();
                    listener.AddConnection(this);
                    last_listener = listener;
                }

                context_bound = true;
                listener.RegisterContext(context);
                return;
            }
            stream.BeginRead(buffer, 0, BufferSize, onread_cb, this);
        }