forked from skumlos/ihcserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIHCHTTPServer.cpp
More file actions
47 lines (41 loc) · 1.17 KB
/
IHCHTTPServer.cpp
File metadata and controls
47 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "IHCHTTPServer.h"
#include "IHCHTTPServerWorker.h"
#include "IHCServer.h"
#include "IHCEvent.h"
#include "IHCInput.h"
#include "IHCOutput.h"
#include "Configuration.h"
#include "IHCServerDefs.h"
#include <sstream>
#include <cstdio>
IHCHTTPServer* IHCHTTPServer::m_instance = NULL;
pthread_mutex_t IHCHTTPServer::m_instanceMutex = PTHREAD_MUTEX_INITIALIZER;
IHCHTTPServer* IHCHTTPServer::getInstance() {
pthread_mutex_lock(&m_instanceMutex);
if(m_instance == NULL) {
Configuration* c = Configuration::getInstance();
std::istringstream portStr(c->getValue(IHCServerDefs::HTTP_PORT_CONFKEY));
int port = 0;
portStr >> port;
if(portStr.fail() || port < 80 || port > 65535) {
port = 8081;
std::ostringstream o;
o << port;
c->setValue(IHCServerDefs::HTTP_PORT_CONFKEY,o.str());
c->save();
}
m_instance = new IHCHTTPServer(port);
}
pthread_mutex_unlock(&m_instanceMutex);
return m_instance;
}
IHCHTTPServer::IHCHTTPServer(int port) :
TCPSocketServer(port)
{
printf("Starting HTTP Server on port %d\n",port);
start();
}
IHCHTTPServer::~IHCHTTPServer() {}
void IHCHTTPServer::clientConnected(TCPSocket* newSocket) {
new IHCHTTPServerWorker(newSocket);
}