Exemplo n.º 1
0
 private void ProcessRequest(object sender, RequestEventArgs e)
 {
     if (m_shutDown)
     {
         return;
     }
     ProcessRequestWorker(e.Socket);
 }
Exemplo n.º 2
0
        private void AcceptRequest(IAsyncResult result)
        {
            m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener, "+HttpRequestListener.AcceptRequest");

            try
            {
                // connected will be false if we've called for an explicit Stop to the server
                //TODO : check why the socket is not connected but it works
                //if ((Environment.OSVersion.Platform == PlatformID.WinCE) && (!m_serverSocket.Connected))
                //{
                //    // NOTE:
                //    // this appears to only be true under CE.  The desktop Connected state is false when the request is accepted.
                //    return;
                //}

                SocketWrapperBase listener = (SocketWrapperBase)result.AsyncState;
                if (listener.IsDisposed)
                {
                    return;
                }

                if (m_serverSocket.IsDisposed || m_shutDown)
                {
                    return;
                }

                SocketWrapperBase handler = listener.EndAccept(result);
                if ((handler == null) || (!handler.Connected))
                {
                    return;
                }

                RequestEventArgs e = new RequestEventArgs(handler);
                var orr            = OnReceiveRequest;
                if (orr != null)
                {
                    orr(this, e);
                }
            }
            catch (Exception ex)
            {
                string text = string.Format("HttpRequestListener.AcceptRequest threw {0}: {1}", ex.GetType().Name, ex.Message);
                m_logProvider.LogPadarnError(text, null);
            }
            finally
            {
                try
                {
                    m_serverSocket.BeginAccept(AcceptRequest, m_serverSocket);
                }
                catch (ObjectDisposedException)
                {
                    // this may occur on server shutdown - swallow it and move on
                }

                m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener, "-HttpRequestListener.AcceptRequest");
            }
        }