mirror of
https://github.com/opensim/opensim.git
synced 2026-08-10 19:36:07 +08:00
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
This commit is contained in:
@@ -37,6 +37,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId);
|
||||
|
||||
public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId);
|
||||
public delegate void DropMethod(UUID requestID, UUID pId);
|
||||
|
||||
public class PollServiceEventArgs : EventArgs
|
||||
{
|
||||
@@ -44,6 +45,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
public GetEventsMethod GetEvents;
|
||||
public NoEventsMethod NoEvents;
|
||||
public RequestMethod Request;
|
||||
public DropMethod Drop;
|
||||
public UUID Id;
|
||||
public int TimeOutms;
|
||||
public EventType Type;
|
||||
@@ -73,13 +75,14 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
RequestMethod pRequest,
|
||||
string pUrl,
|
||||
HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,
|
||||
UUID pId, int pTimeOutms)
|
||||
DropMethod pDrop, UUID pId, int pTimeOutms)
|
||||
{
|
||||
Request = pRequest;
|
||||
Url = pUrl;
|
||||
HasEvents = pHasEvents;
|
||||
GetEvents = pGetEvents;
|
||||
NoEvents = pNoEvents;
|
||||
Drop = pDrop;
|
||||
Id = pId;
|
||||
TimeOutms = pTimeOutms;
|
||||
Type = EventType.LongPoll;
|
||||
|
||||
@@ -160,6 +160,19 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
}
|
||||
}
|
||||
|
||||
public void DropByContext(PollServiceHttpRequest req)
|
||||
{
|
||||
Queue<PollServiceHttpRequest> 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)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
|
||||
{
|
||||
Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);
|
||||
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))
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user