reduce default http keepalive to just 30s because to viewers connections flood.

master
UbitUmarov 2020-07-24 19:19:16 +01:00
parent d9a680703f
commit e08ca7402c
2 changed files with 16 additions and 24 deletions

View File

@ -276,22 +276,24 @@ namespace OSHttpServer
if (context.TriggerKeepalive)
{
context.TriggerKeepalive = false;
context.MonitorKeepaliveStartMS = nowMS + 1;
context.MonitorKeepaliveStartMS = nowMS + 500;
return false;
}
if (context.MonitorKeepaliveStartMS != 0)
{
if (context.IsClosing)
{
disconnectError = SocketError.Success;
return true;
}
if (EnvironmentTickCountAdd(context.TimeoutKeepAlive, context.MonitorKeepaliveStartMS) < nowMS)
{
if(context.IsClosing)
disconnectError = SocketError.Success;
else
disconnectError = SocketError.TimedOut;
disconnectError = SocketError.TimedOut;
context.MonitorKeepaliveStartMS = 0;
return true;
}
return false;
}
if (EnvironmentTickCountAdd(context.TimeoutMaxIdle, context.LastActivityTimeMS) < nowMS)

View File

@ -46,7 +46,7 @@ namespace OSHttpServer
public int TimeoutRequestReceived = 30000; // 30 seconds
public int TimeoutMaxIdle = 180000; // 3 minutes
public int m_TimeoutKeepAlive = 60000;
public int m_TimeoutKeepAlive = 30000;
public bool FirstRequestLineReceived;
public bool FullRequestReceived;
@ -444,7 +444,7 @@ namespace OSHttpServer
if (m_maxRequests == 0)
return;
if(--m_maxRequests == 0)
if (--m_maxRequests == 0)
m_currentRequest.Connection = ConnectionType.Close;
if(m_currentRequest.Uri == null)
@ -527,8 +527,7 @@ namespace OSHttpServer
if(contextID < 0)
return;
bool doclose = ctype == ConnectionType.Close;
if (doclose)
if (ctype == ConnectionType.Close)
{
m_isClosing = true;
m_requests.Clear();
@ -538,30 +537,21 @@ namespace OSHttpServer
else
{
LastActivityTimeMS = ContextTimeoutManager.EnvironmentTickCount();
if (Stream != null && Stream.CanWrite)
{
ContextTimeoutManager.ContextEnterActiveSend();
try
{
await Stream.FlushAsync().ConfigureAwait(false);
}
catch
{
};
ContextTimeoutManager.ContextLeaveActiveSend();
}
if (Stream == null || !Stream.CanWrite)
return;
TriggerKeepalive = true;
HttpRequest nextRequest = null;
lock (m_requestsLock)
{
if (m_requests != null && m_requests.Count > 0)
nextRequest = m_requests.Dequeue();
if (nextRequest != null && RequestReceived != null)
{
m_waitingResponse = true;
TriggerKeepalive = false;
}
else
TriggerKeepalive = true;
}
if (nextRequest != null)
RequestReceived?.Invoke(this, new RequestEventArgs(nextRequest));