do http requests serialization at lower level
parent
ab14241871
commit
1ad3a256f2
|
@ -25,11 +25,15 @@ namespace OSHttpServer
|
||||||
|
|
||||||
static private int basecontextID;
|
static private int basecontextID;
|
||||||
|
|
||||||
|
Queue<HttpRequest> m_requests;
|
||||||
|
object m_requestsLock = new object();
|
||||||
|
public int m_maxRequests = MAXREQUESTS;
|
||||||
|
public bool m_waitingResponse;
|
||||||
|
|
||||||
private readonly byte[] m_ReceiveBuffer;
|
private readonly byte[] m_ReceiveBuffer;
|
||||||
private int m_ReceiveBytesLeft;
|
private int m_ReceiveBytesLeft;
|
||||||
private ILogWriter m_log;
|
private ILogWriter m_log;
|
||||||
private readonly IHttpRequestParser m_parser;
|
private readonly IHttpRequestParser m_parser;
|
||||||
private HashSet<uint> requestsInServiceIDs;
|
|
||||||
private Socket m_sock;
|
private Socket m_sock;
|
||||||
|
|
||||||
public bool Available = true;
|
public bool Available = true;
|
||||||
|
@ -44,8 +48,6 @@ namespace OSHttpServer
|
||||||
public int TimeoutMaxIdle = 180000; // 3 minutes
|
public int TimeoutMaxIdle = 180000; // 3 minutes
|
||||||
public int m_TimeoutKeepAlive = 60000;
|
public int m_TimeoutKeepAlive = 60000;
|
||||||
|
|
||||||
public int m_maxRequests = MAXREQUESTS;
|
|
||||||
|
|
||||||
public bool FirstRequestLineReceived;
|
public bool FirstRequestLineReceived;
|
||||||
public bool FullRequestReceived;
|
public bool FullRequestReceived;
|
||||||
|
|
||||||
|
@ -126,7 +128,7 @@ namespace OSHttpServer
|
||||||
m_sock = sock;
|
m_sock = sock;
|
||||||
|
|
||||||
m_ReceiveBuffer = new byte[16384];
|
m_ReceiveBuffer = new byte[16384];
|
||||||
requestsInServiceIDs = new HashSet<uint>();
|
m_requests = new Queue<HttpRequest>();
|
||||||
|
|
||||||
SSLCommonName = "";
|
SSLCommonName = "";
|
||||||
if (secured)
|
if (secured)
|
||||||
|
@ -179,9 +181,9 @@ namespace OSHttpServer
|
||||||
{
|
{
|
||||||
if (string.Compare(e.Name, "expect", true) == 0 && e.Value.Contains("100-continue"))
|
if (string.Compare(e.Name, "expect", true) == 0 && e.Value.Contains("100-continue"))
|
||||||
{
|
{
|
||||||
lock (requestsInServiceIDs)
|
lock (m_requestsLock)
|
||||||
{
|
{
|
||||||
if (requestsInServiceIDs.Count == 0)
|
if (m_maxRequests == MAXREQUESTS)
|
||||||
Respond("HTTP/1.1", HttpStatusCode.Continue, null);
|
Respond("HTTP/1.1", HttpStatusCode.Continue, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +239,8 @@ namespace OSHttpServer
|
||||||
m_currentRequest = null;
|
m_currentRequest = null;
|
||||||
m_currentResponse?.Clear();
|
m_currentResponse?.Clear();
|
||||||
m_currentResponse = null;
|
m_currentResponse = null;
|
||||||
requestsInServiceIDs.Clear();
|
m_requests.Clear();
|
||||||
|
m_requests = null;
|
||||||
m_parser.Clear();
|
m_parser.Clear();
|
||||||
|
|
||||||
FirstRequestLineReceived = false;
|
FirstRequestLineReceived = false;
|
||||||
|
@ -464,27 +467,23 @@ namespace OSHttpServer
|
||||||
|
|
||||||
m_currentRequest.Body.Seek(0, SeekOrigin.Begin);
|
m_currentRequest.Body.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
int nreqs;
|
bool donow = true;
|
||||||
lock (requestsInServiceIDs)
|
lock (m_requestsLock)
|
||||||
{
|
{
|
||||||
nreqs = requestsInServiceIDs.Count;
|
if(m_waitingResponse)
|
||||||
requestsInServiceIDs.Add(m_currentRequest.ID);
|
{
|
||||||
|
m_requests.Enqueue(m_currentRequest);
|
||||||
|
donow = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_waitingResponse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for now pipeline requests need to be serialized by opensim
|
// for now pipeline requests need to be serialized by opensim
|
||||||
|
if(donow)
|
||||||
RequestReceived?.Invoke(this, new RequestEventArgs(m_currentRequest));
|
RequestReceived?.Invoke(this, new RequestEventArgs(m_currentRequest));
|
||||||
|
|
||||||
m_currentRequest = new HttpRequest(this);
|
m_currentRequest = new HttpRequest(this);
|
||||||
|
|
||||||
int nreqsnow;
|
|
||||||
lock (requestsInServiceIDs)
|
|
||||||
{
|
|
||||||
nreqsnow = requestsInServiceIDs.Count;
|
|
||||||
}
|
|
||||||
if (nreqs != nreqsnow)
|
|
||||||
{
|
|
||||||
// request was not done by us
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartSendResponse(HttpResponse response)
|
public void StartSendResponse(HttpResponse response)
|
||||||
|
@ -524,20 +523,10 @@ namespace OSHttpServer
|
||||||
m_currentResponse = null;
|
m_currentResponse = null;
|
||||||
|
|
||||||
bool doclose = ctype == ConnectionType.Close;
|
bool doclose = ctype == ConnectionType.Close;
|
||||||
lock (requestsInServiceIDs)
|
|
||||||
{
|
|
||||||
requestsInServiceIDs.Remove(requestID);
|
|
||||||
if (requestsInServiceIDs.Count > 1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doclose)
|
if (doclose)
|
||||||
{
|
{
|
||||||
m_isClosing = true;
|
m_isClosing = true;
|
||||||
lock (requestsInServiceIDs)
|
m_requests.Clear();
|
||||||
requestsInServiceIDs.Clear();
|
|
||||||
|
|
||||||
TriggerKeepalive = true;
|
TriggerKeepalive = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -557,10 +546,22 @@ namespace OSHttpServer
|
||||||
ContextTimeoutManager.ContextLeaveActiveSend();
|
ContextTimeoutManager.ContextLeaveActiveSend();
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (requestsInServiceIDs)
|
if (Stream == null || !Stream.CanWrite)
|
||||||
{
|
return;
|
||||||
if (requestsInServiceIDs.Count == 0)
|
|
||||||
TriggerKeepalive = true;
|
TriggerKeepalive = true;
|
||||||
|
lock (m_requestsLock)
|
||||||
|
{
|
||||||
|
m_waitingResponse = false;
|
||||||
|
if (m_requests != null && m_requests.Count > 0)
|
||||||
|
{
|
||||||
|
HttpRequest nextRequest = m_requests.Dequeue();
|
||||||
|
if (nextRequest != null)
|
||||||
|
{
|
||||||
|
m_waitingResponse = true;
|
||||||
|
RequestReceived?.Invoke(this, new RequestEventArgs(nextRequest));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue