a few more changes to oshttp send

This commit is contained in:
UbitUmarov
2021-09-04 14:49:42 +01:00
parent 52753972ee
commit affaacb279
3 changed files with 24 additions and 12 deletions

View File

@@ -299,7 +299,7 @@ namespace OSHttpServer
m_contexts.Enqueue(context);
}
public static void EnqueueSend(HttpClientContext context, int priority, bool notThrottled = true)
public static void EnqueueSend(HttpClientContext context, int priority)
{
switch(priority)
{
@@ -315,8 +315,12 @@ namespace OSHttpServer
default:
return;
}
if(notThrottled)
m_processWaitEven.Set();
m_processWaitEven.Set();
}
public static void PulseWaitSend()
{
m_processWaitEven?.Set();
}
public static void ContextEnterActiveSend()

View File

@@ -526,15 +526,14 @@ namespace OSHttpServer
return false;
LastActivityTimeMS = ContextTimeoutManager.EnvironmentTickCount();
m_currentResponse?.SendNextAsync(bytesLimit);
return true;
return m_currentResponse.SendNextAsync(bytesLimit);
}
public void ContinueSendResponse()
{
if(m_currentResponse == null)
return;
ContextTimeoutManager.EnqueueSend(this, m_currentResponse.Priority, true);
ContextTimeoutManager.EnqueueSend(this, m_currentResponse.Priority);
}
public void EndSendResponse(uint requestID, ConnectionType ctype)
@@ -577,6 +576,7 @@ namespace OSHttpServer
if (nextRequest != null)
RequestReceived?.Invoke(this, new RequestEventArgs(nextRequest));
}
ContextTimeoutManager.PulseWaitSend();
}
/// <summary>
@@ -679,18 +679,22 @@ namespace OSHttpServer
private void SendAsyncEnd(IAsyncResult res)
{
bool didleave = false;
try
{
m_stream.EndWrite(res);
ContextTimeoutManager.ContextLeaveActiveSend();
didleave = true;
m_currentResponse.CheckSendNextAsyncContinue();
}
catch (Exception e)
{
e.GetHashCode();
if(m_stream != null)
if (m_stream != null)
Disconnect(SocketError.NoRecovery);
}
ContextTimeoutManager.ContextLeaveActiveSend();
if(!didleave)
ContextTimeoutManager.ContextLeaveActiveSend();
}
public bool SendAsyncStart(byte[] buffer, int offset, int size)

View File

@@ -359,7 +359,7 @@ namespace OSHttpServer
m_context.StartSendResponse(this);
}
public void SendNextAsync(int bytesLimit)
public bool SendNextAsync(int bytesLimit)
{
if (m_headerBytes != null)
{
@@ -375,8 +375,9 @@ namespace OSHttpServer
}
RawBuffer = null;
Sent = true;
return false;
}
return;
return true;
}
bool sendRes;
@@ -412,8 +413,9 @@ namespace OSHttpServer
m_body = null;
}
Sent = true;
return false;
}
return;
return true;
}
else
RawBuffer = null;
@@ -455,8 +457,9 @@ namespace OSHttpServer
{
RawBuffer = null;
Sent = true;
return false;
}
return;
return true;
}
else
RawBuffer = null;
@@ -470,6 +473,7 @@ namespace OSHttpServer
Sent = true;
m_context.EndSendResponse(requestID, Connection);
return false;
}
public void CheckSendNextAsyncContinue()