forked from georgesofianosgr/HTTP-Web-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpserver.h
45 lines (33 loc) · 984 Bytes
/
httpserver.h
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
#ifndef HTPPSERVER_H
#define HTPPSERVER_H
#include <functional>
#include <string>
#include <winsock2.h>
#include <ws2tcpip.h>
#define DEFAULT_PORT 8080
namespace web
{
class HttpServer
{
std::function<void (const std::string&)> _logging;
WORD _socketVersion;
WSADATA _wsaData;
SOCKET _listeningSocket;
addrinfo _hints,*_result;
int _maxConnections;
// Server Info
int _port;
public:
HttpServer(int port = DEFAULT_PORT);
void SetLogging(std::function<void (const std::string&)> logging);
int Port() const;
void SetPort(int port);
std::string LocalUrl() const;
bool Init(); // Initialize Server
bool Start(); // Start server
void WaitForRequests(std::function<int (const class Request&, class Response &)> onConnection);
void Stop(); // Close Server
static void handleRequest(std::function<int (const class Request&, class Response &)> onConnection, class Request request);
};
}
#endif // HTPPSERVER_H