From 442b27222828381a27c7c5eddc967a0de4c82d0a Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 17 Jul 2016 13:20:56 +0100 Subject: add a Drop method to PollService Event handlers, Drop requests on connections known to be lost or delay event check if they are sending a response --- .../HttpServer/PollServiceRequestManager.cs | 95 ++++++++++++++-------- 1 file changed, 63 insertions(+), 32 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index ffcad0f..5b40590 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -160,6 +160,19 @@ namespace OpenSim.Framework.Servers.HttpServer } } + public void DropByContext(PollServiceHttpRequest req) + { + Queue ctxQeueue; + lock (m_bycontext) + { + if (m_bycontext.TryGetValue(req, out ctxQeueue)) + { + ctxQeueue.Clear(); + m_bycontext.Remove(req); + } + } + } + public void EnqueueInt(PollServiceHttpRequest req) { if (m_running) @@ -263,22 +276,61 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceHttpRequest req = m_requests.Dequeue(5000); Watchdog.UpdateThread(); - if (req != null) + if(req == null) + continue; + + try { - try + if(!req.HttpContext.CanSend()) { - if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) + req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); + byContextDequeue(req); + continue; + } + + if(req.HttpContext.IsSending()) + { + if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); + req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); + byContextDequeue(req); + } + else + ReQueueEvent(req); + continue; + } + 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, responsedata); + req.DoHTTPGruntWork(m_server, + req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); byContextDequeue(req); } - catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + catch (ObjectDisposedException) { // Ignore it, no need to reply } @@ -287,36 +339,15 @@ namespace OpenSim.Framework.Servers.HttpServer } 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); - } + ReQueueEvent(req); } } - catch (Exception e) - { - m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); - } + } + catch (Exception e) + { + m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); } } } - } } -- cgit v1.1