Esempio n. 1
0
            public PollServiceTextureEventArgs(UUID pId, Scene scene) :
                base(null, "", null, null, null, pId, int.MaxValue)
            {
                m_scene = scene;
                // x is request id, y is userid
                HasEvents = (x, y) =>
                {
                    lock (responses)
                    {
                        bool ret = m_throttler.hasEvents(x, responses);
                        return(ret);
                    }
                };
                GetEvents = (x, y) =>
                {
                    lock (responses)
                    {
                        try
                        {
                            return(responses[x].response);
                        }
                        finally
                        {
                            responses.Remove(x);
                            m_throttler.PassTime();
                        }
                    }
                };
                // x is request id, y is request data hashtable
                Request = (x, y) =>
                {
                    aPollRequest reqinfo = new aPollRequest();
                    reqinfo.thepoll = this;
                    reqinfo.reqID   = x;
                    reqinfo.request = y;
                    reqinfo.send503 = false;

                    lock (responses)
                    {
                        if (responses.Count > 0)
                        {
                            if (m_queue.Count() >= 4)
                            {
                                // Never allow more than 4 fetches to wait
                                reqinfo.send503 = true;
                            }
                        }
                    }
                    m_queue.Enqueue(reqinfo);
                    m_throttler.PassTime();
                };

                // this should never happen except possible on shutdown
                NoEvents = (x, y) =>
                {
/*
 *                  lock (requests)
 *                  {
 *                      Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
 *                      requests.Remove(request);
 *                  }
 */
                    Hashtable response = new Hashtable();

                    response["int_response_code"]   = 500;
                    response["str_response_string"] = "Script timeout";
                    response["content_type"]        = "text/plain";
                    response["keepalive"]           = false;
                    response["reusecontext"]        = false;

                    return(response);
                };
            }
Esempio n. 2
0
            public void Process(APollRequest requestinfo)
            {
                Hashtable response;

                UUID requestID = requestinfo.reqID;

                if (m_scene.ShuttingDown)
                {
                    return;
                }

                lock (responses)
                {
                    lock (dropedResponses)
                    {
                        if (dropedResponses.Contains(requestID))
                        {
                            dropedResponses.Remove(requestID);
                            return;
                        }
                    }

                    if (requestinfo.send503)
                    {
                        response = new Hashtable();

                        response["int_response_code"]   = 503;
                        response["str_response_string"] = "Throttled";
                        response["content_type"]        = "text/plain";
                        response["keepalive"]           = false;
                        response["reusecontext"]        = false;

                        Hashtable headers = new Hashtable();
                        headers["Retry-After"] = 30;
                        response["headers"]    = headers;

                        responses[requestID] = new APollResponse()
                        {
                            bytes = 0, response = response
                        };

                        return;
                    }

                    // If the avatar is gone, don't bother to get the texture
                    if (m_scene.GetScenePresence(Id) == null)
                    {
                        response = new Hashtable();

                        response["int_response_code"]   = 500;
                        response["str_response_string"] = "Script timeout";
                        response["content_type"]        = "text/plain";
                        response["keepalive"]           = false;

                        responses[requestID] = new APollResponse()
                        {
                            bytes = 0, response = response
                        };

                        return;
                    }
                }

                response = m_getTextureHandler.Handle(requestinfo.request);

                lock (responses)
                {
                    lock (dropedResponses)
                    {
                        if (dropedResponses.Contains(requestID))
                        {
                            dropedResponses.Remove(requestID);
                            m_throttler.PassTime();
                            return;
                        }
                    }
                    responses[requestID] = new APollResponse()
                    {
                        bytes    = (int)response["int_bytes"],
                        response = response
                    };
                }
                m_throttler.PassTime();
            }