// work threads

        private void PoolWorkerJob(object o)
        {
            PollServiceHttpRequest req = o as PollServiceHttpRequest;

            if (req == null)
            {
                return;
            }
            try
            {
                if (!req.Request.Context.CanSend())
                {
                    req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                    return;
                }

                if (!m_running)
                {
                    req.DoHTTPstop();
                    return;
                }

                if (req.Request.Context.IsSending())
                {
                    ReQueueEvent(req);
                    return;
                }

                if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                {
                    try
                    {
                        Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);
                        req.DoHTTPGruntWork(responsedata);
                    }
                    catch { }
                }
                else
                {
                    if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                    {
                        try
                        {
                            req.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                        }
                        catch { }
                    }
                    else
                    {
                        ReQueueEvent(req);
                    }
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
            }
        }
Beispiel #2
0
        public void WaitPerformResponse()
        {
            PollServiceHttpRequest req = m_requests.Dequeue(5000);

            //            m_log.DebugFormat("[YYY]: Dequeued {0}", (req == null ? "null" : req.PollServiceArgs.Type.ToString()));

            if (req != null)
            {
                try
                {
                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);

                        if (responsedata == null)
                        {
                            return;
                        }

                        // This is the event queue.
                        // Even if we're not running we can still perform responses by explicit request.
                        if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll ||
                            !PerformResponsesAsync)
                        {
                            try
                            {
                                ResponsesProcessed++;
                                req.DoHTTPGruntWork(m_server, responsedata);
                            }
                            catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream
                            {
                                // Ignore it, no need to reply
                                m_log.Error(e);
                            }
                        }
                        else
                        {
                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    ResponsesProcessed++;
                                    req.DoHTTPGruntWork(m_server, responsedata);
                                }
                                catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream
                                {
                                    // Ignore it, no need to reply
                                    m_log.Error(e);
                                }
                                catch (Exception e)
                                {
                                    m_log.Error(e);
                                }

                                return(null);
                            }, null);
                        }
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            ResponsesProcessed++;
                            req.DoHTTPGruntWork(
                                m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }
Beispiel #3
0
        // work threads

        private void PoolWorkerJob()
        {
            while (m_running)
            {
                PollServiceHttpRequest req = m_requests.Dequeue(4500);
                Watchdog.UpdateThread();
                if (req == null)
                {
                    continue;
                }

                try
                {
                    if (!req.HttpContext.CanSend())
                    {
                        req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                        byContextDequeue(req);
                        continue;
                    }

                    if (req.HttpContext.IsSending())
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                            byContextDequeue(req);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                        continue;
                    }

                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        m_threadPool.QueueWorkItem(x =>
                        {
                            try
                            {
                                Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);
                                req.DoHTTPGruntWork(m_server, responsedata);
                            }
                            catch (ObjectDisposedException) { }
                            finally
                            {
                                byContextDequeue(req);
                            }
                            return(null);
                        }, null);
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    req.DoHTTPGruntWork(m_server,
                                                        req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                                }
                                catch (ObjectDisposedException) {}
                                finally
                                {
                                    byContextDequeue(req);
                                }
                                return(null);
                            }, null);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }
        // work threads

        private void PoolWorkerJob()
        {
            while (m_running)
            {
                PollServiceHttpRequest req = m_requests.Dequeue(5000);

                Watchdog.UpdateThread();
                if (req != null)
                {
                    try
                    {
                        if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                        {
                            Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);

                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    req.DoHTTPGruntWork(m_server, responsedata);
                                    byContextDequeue(req);
                                }
                                catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
                                {
                                    // Ignore it, no need to reply
                                }
                                return(null);
                            }, null);
                        }
                        else
                        {
                            if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                            {
                                m_threadPool.QueueWorkItem(x =>
                                {
                                    try
                                    {
                                        req.DoHTTPGruntWork(m_server,
                                                            req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                                        byContextDequeue(req);
                                    }
                                    catch (ObjectDisposedException)
                                    {
                                        // Ignore it, no need to reply
                                    }
                                    return(null);
                                }, null);
                            }
                            else
                            {
                                ReQueueEvent(req);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                    }
                }
            }
        }
        // work threads

        private void PoolWorkerJob()
        {
            PollServiceHttpRequest req;

            while (m_running)
            {
                try
                {
                    req = null;
                    if (!m_requests.TryTake(out req, 4500) || req == null)
                    {
                        Watchdog.UpdateThread();
                        continue;
                    }

                    Watchdog.UpdateThread();

                    if (!req.HttpContext.CanSend())
                    {
                        req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                        byContextDequeue(req);
                        continue;
                    }

                    if (req.HttpContext.IsSending())
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                            byContextDequeue(req);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                        continue;
                    }

                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        PollServiceHttpRequest nreq = req;
                        m_threadPool.QueueWorkItem(x =>
                        {
                            try
                            {
                                Hashtable responsedata = nreq.PollServiceArgs.GetEvents(nreq.RequestID, nreq.PollServiceArgs.Id);
                                nreq.DoHTTPGruntWork(responsedata);
                            }
                            catch (ObjectDisposedException) { }
                            finally
                            {
                                byContextDequeue(nreq);
                                nreq = null;
                            }
                            return(null);
                        }, null);
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            PollServiceHttpRequest nreq = req;
                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    nreq.DoHTTPGruntWork(nreq.PollServiceArgs.NoEvents(nreq.RequestID, nreq.PollServiceArgs.Id));
                                }
                                catch (ObjectDisposedException) { }
                                finally
                                {
                                    byContextDequeue(nreq);
                                    nreq = null;
                                }
                                return(null);
                            }, null);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                    // Shouldn't set this to 'false', the normal shutdown should cause things to exit
                    // but robust is still not normal neither is mono
                    m_running = false;
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }