public void Run()
        {
            while (m_running)
            {
                PollServiceHttpRequest req = m_request.Dequeue();

                Watchdog.UpdateThread();

                try
                {
                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        StreamReader str;
                        try
                        {
                            str = new StreamReader(req.Request.Body);
                        }
                        catch (System.ArgumentException)
                        {
                            // Stream was not readable means a child agent
                            // was closed due to logout, leaving the
                            // Event Queue request orphaned.
                            continue;
                        }

                        Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd());
                        m_server.DoHTTPGruntWork(responsedata,
                                                 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > m_timeout)
                        {
                            m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id),
                                                     new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
                        }
                        else
                        {
                            ReQueuePollServiceItem reQueueItem = ReQueue;
                            if (reQueueItem != null)
                            {
                                reQueueItem(req);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }
Esempio n. 2
0
        internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
        {
            OSHttpResponse response
                = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext);

            byte[] buffer = server.DoHTTPGruntWork(responsedata, response);

            if (Request.Body.CanRead)
            {
                Request.Body.Dispose();
            }

            response.SendChunked     = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;
            response.ReuseContext    = false;

            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
                response.OutputStream.Flush();
                response.Send();
                buffer = null;
            }
            catch (Exception ex)
            {
                m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex);
            }

            PollServiceArgs.RequestsHandled++;
        }
        internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
        {
            OSHttpResponse response
                = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext);

            byte[] buffer = server.DoHTTPGruntWork(responsedata, response);

            if (Request.Body.CanRead)
            {
                Request.Body.Dispose();
            }

            response.SendChunked     = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
                response.Send();
                buffer = null;
            }
            catch (Exception ex)
            {
                if (ex is System.Net.Sockets.SocketException)
                {
                    // only mute connection reset by peer so we are not totally blind for now
                    if (((System.Net.Sockets.SocketException)ex).SocketErrorCode != System.Net.Sockets.SocketError.ConnectionReset)
                    {
                        m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex);
                    }
                }
                else
                {
                    m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex);
                }
            }

            PollServiceArgs.RequestsHandled++;
        }
        internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
        {
            OSHttpResponse response
                = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext);

            byte[] buffer = server.DoHTTPGruntWork(responsedata, response);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex));
            }
            finally
            {
                //response.OutputStream.Close();
                try
                {
                    response.OutputStream.Flush();
                    response.Send();

                    //if (!response.KeepAlive && response.ReuseContext)
                    //    response.FreeContext();
                }
                catch (Exception e)
                {
                    m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e));
                }

                PollServiceArgs.RequestsHandled++;
            }
        }