now limiting number of simultaneous HTTP requests being handled
at once. this is to prevent denial of service.
This commit is contained in:
parent
d2135af0d9
commit
fa4d24216f
|
@ -9,8 +9,7 @@ class CStopwatch;
|
||||||
class CCondVarBase {
|
class CCondVarBase {
|
||||||
public:
|
public:
|
||||||
// mutex must be supplied. all condition variables have an
|
// mutex must be supplied. all condition variables have an
|
||||||
// associated mutex. the copy c'tor uses the same mutex as the
|
// associated mutex.
|
||||||
// argument and is otherwise like the default c'tor.
|
|
||||||
CCondVarBase(CMutex* mutex);
|
CCondVarBase(CMutex* mutex);
|
||||||
~CCondVarBase();
|
~CCondVarBase();
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,15 @@ else { wait(0); exit(1); }
|
||||||
// CServer
|
// CServer
|
||||||
//
|
//
|
||||||
|
|
||||||
|
const SInt32 CServer::s_httpMaxSimultaneousRequests = 3;
|
||||||
|
|
||||||
CServer::CServer() : m_primary(NULL),
|
CServer::CServer() : m_primary(NULL),
|
||||||
m_active(NULL),
|
m_active(NULL),
|
||||||
m_primaryInfo(NULL),
|
m_primaryInfo(NULL),
|
||||||
m_seqNum(0),
|
m_seqNum(0),
|
||||||
m_httpServer(NULL)
|
m_httpServer(NULL),
|
||||||
|
m_httpAvailable(&m_mutex,
|
||||||
|
s_httpMaxSimultaneousRequests)
|
||||||
{
|
{
|
||||||
m_socketFactory = NULL;
|
m_socketFactory = NULL;
|
||||||
m_securityFactory = NULL;
|
m_securityFactory = NULL;
|
||||||
|
@ -1128,6 +1132,16 @@ void CServer::acceptHTTPClients(void*)
|
||||||
// accept connections and begin processing them
|
// accept connections and begin processing them
|
||||||
log((CLOG_DEBUG1 "waiting for HTTP connections"));
|
log((CLOG_DEBUG1 "waiting for HTTP connections"));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
// limit the number of HTTP requests being handled at once
|
||||||
|
{
|
||||||
|
CLock lock(&m_httpAvailable);
|
||||||
|
while (m_httpAvailable == 0) {
|
||||||
|
m_httpAvailable.wait();
|
||||||
|
}
|
||||||
|
assert(m_httpAvailable > 0);
|
||||||
|
m_httpAvailable = m_httpAvailable - 1;
|
||||||
|
}
|
||||||
|
|
||||||
// accept connection
|
// accept connection
|
||||||
CThread::testCancel();
|
CThread::testCancel();
|
||||||
ISocket* socket = listen->accept();
|
ISocket* socket = listen->accept();
|
||||||
|
@ -1141,6 +1155,7 @@ void CServer::acceptHTTPClients(void*)
|
||||||
}
|
}
|
||||||
catch (XBase& e) {
|
catch (XBase& e) {
|
||||||
log((CLOG_ERR "cannot listen for HTTP clients: %s", e.what()));
|
log((CLOG_ERR "cannot listen for HTTP clients: %s", e.what()));
|
||||||
|
// FIXME -- quit?
|
||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1163,9 +1178,21 @@ void CServer::processHTTPRequest(void* vsocket)
|
||||||
// clean up
|
// clean up
|
||||||
socket->close();
|
socket->close();
|
||||||
delete socket;
|
delete socket;
|
||||||
|
|
||||||
|
// increment available HTTP handlers
|
||||||
|
{
|
||||||
|
CLock lock(&m_httpAvailable);
|
||||||
|
m_httpAvailable = m_httpAvailable + 1;
|
||||||
|
m_httpAvailable.signal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
delete socket;
|
delete socket;
|
||||||
|
{
|
||||||
|
CLock lock(&m_httpAvailable);
|
||||||
|
m_httpAvailable = m_httpAvailable + 1;
|
||||||
|
m_httpAvailable.signal();
|
||||||
|
}
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "MouseTypes.h"
|
#include "MouseTypes.h"
|
||||||
#include "CConfig.h"
|
#include "CConfig.h"
|
||||||
#include "CClipboard.h"
|
#include "CClipboard.h"
|
||||||
|
#include "CCondVar.h"
|
||||||
#include "CMutex.h"
|
#include "CMutex.h"
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
#include "CThread.h"
|
#include "CThread.h"
|
||||||
|
@ -235,8 +236,10 @@ private:
|
||||||
|
|
||||||
CClipboardInfo m_clipboards[kClipboardEnd];
|
CClipboardInfo m_clipboards[kClipboardEnd];
|
||||||
|
|
||||||
// server for processing HTTP requests
|
// HTTP request processing stuff
|
||||||
CHTTPServer* m_httpServer;
|
CHTTPServer* m_httpServer;
|
||||||
|
CCondVar<SInt32> m_httpAvailable;
|
||||||
|
static const SInt32 s_httpMaxSimultaneousRequests;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue