WebSocketSharp.Net.HttpListener.RegisterContext C# (CSharp) Method

RegisterContext() private method

private RegisterContext ( HttpListenerContext context ) : void
context HttpListenerContext
return void
        internal void RegisterContext(HttpListenerContext context)
        {
            lock (((ICollection)registry).SyncRoot)
                registry [context] = context;

            ListenerAsyncResult ares = null;
            lock (((ICollection)wait_queue).SyncRoot) {
                if (wait_queue.Count == 0) {
                    lock (((ICollection)ctx_queue).SyncRoot)
                        ctx_queue.Add (context);
                } else {
                    ares = wait_queue [0];
                    wait_queue.RemoveAt (0);
                }
            }

            if (ares != null)
                ares.Complete (context);
        }

Usage Example

Example #1
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);
        }
All Usage Examples Of WebSocketSharp.Net.HttpListener::RegisterContext