-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.cpp
62 lines (43 loc) · 1.09 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include "include/stdafx.h"
#include "include/handler.h"
using namespace std;
using namespace web;
using namespace http;
using namespace utility;
using namespace http::experimental::listener;
std::unique_ptr<handler> g_httpHandler;
void on_initialize(const string_t& address)
{
uri_builder uri(address);
auto addr = uri.to_uri().to_string();
g_httpHandler = std::unique_ptr<handler>(new handler(addr));
g_httpHandler->open().wait();
ucout << utility::string_t(U("Listening for requests at: ")) << addr << std::endl;
return;
}
void on_shutdown()
{
g_httpHandler->close().wait();
return;
}
#ifdef _WIN32
int wmain(int argc, wchar_t *argv[])
#else
int main(int argc, char *argv[])
#endif
{
utility::string_t port = U("34568");
if(argc == 2)
{
port = argv[1];
}
utility::string_t address = U("http://127.0.0.1:");
address.append(port);
on_initialize(address);
std::cout << "Press ENTER to exit." << std::endl;
std::string line;
std::getline(std::cin, line);
on_shutdown();
return 0;
}