Exemplo n.º 1
0
        // ProcessHttpRequest is the async handler for new http requests
        // This function should do what it needs to do and then exit
        public static void ProcessHttpRequest(IAsyncResult result)
        {
            RequestProcessor rp = null;
            try   // (IAsyncResult)result will be invalid if we've killed the listener
            {
                HttpListener listener = (HttpListener)result.AsyncState;
                HttpListenerContext context = listener.EndGetContext(result);  // Call EndGetContext to complete the asynchronous operation.

                // Obtain a response object.
                HttpListenerResponse response = context.Response;

                // Create a new request processor
                rp = new RequestProcessor(context);

                rp.Run();
            }
            catch (System.ObjectDisposedException)
            {
                // Do nothing
            }
            catch (Exception ex)
            {
                Functions.WriteLineToLogFile("Process HttpRequest Exception:");
                Functions.WriteExceptionToLogFile(ex);
            }
            finally
            {
                if (rp != null)
                {
                    rp.Dispose();
                    rp = null;
                }
            }
        }
Exemplo n.º 2
0
        protected void WebRequestCallback(IAsyncResult result)
        {
            if (myHttpListener == null) return;
            if (!Active) return;

            try
            {
                // Get out the context object
                HttpListenerContext context = myHttpListener.EndGetContext(result);

                // *** Immediately set up the next context
                myHttpListener.BeginGetContext(new AsyncCallback(WebRequestCallback), myHttpListener);

                RequestProcessor rp = new RequestProcessor(context);
                rp.UserAgentConnected += new EventHandler<MessageEventArgs>(rp_UserAgentConnected);
                rp.Run();
                rp.Dispose();
                rp = null;
                // done
                //RPStackSizeChanged(this, new GenericEventArgs<int>(--numberOfRequestProcessors));
            }
            catch (Exception ex)
            {
                Functions.WriteLineToLogFile("Exception thrown processing web server request: ");
                Functions.WriteExceptionToLogFile(ex);
            }

            return;
        }
Exemplo n.º 3
0
 public void Subscribe(RequestProcessor m)
 {
     m.RestartRP += new RequestProcessor.RestartRPHandler(HeardIt);
 }