-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.cpp
42 lines (34 loc) · 931 Bytes
/
Server.cpp
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
#include <string>
#include "headers/Server.h"
extern "C" {
#include "headers/mongoose.h"
}
/// <summary>
/// Run server with event handler options
/// </summary>
/// <returns>False if connection to the server failed</returns>
bool Server::runServer()
{
struct mg_mgr eManager;
struct mg_connection* connector;
// Run Mongoose server
mg_mgr_init(&eManager);
connector = mg_http_listen(&eManager, address, eHandler, &eManager);
// Connection failed
if (connector == NULL) {
return false;
}
while (true) mg_mgr_poll(&eManager, 1000); // Run the server
mg_mgr_free(&eManager);
return true;
}
/**
* Standard event handler implementation
*/
void eHandler(struct mg_connection* connector, int ev, void* ev_data, void* fn_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_serve_opts opts = { "./serverdir", "#.shtml" };
mg_http_serve_dir(connector, (struct mg_http_message*)ev_data, &opts);
}
(void)fn_data;
}