13 #include <boost/asio.hpp>
14 #include <boost/bind.hpp>
15 #include <boost/function.hpp>
16 #include <boost/lexical_cast.hpp>
21 boost::function0<void> console_ctrl_function;
23 BOOL WINAPI console_ctrl_handler(DWORD ctrl_type) {
26 case CTRL_BREAK_EVENT:
27 case CTRL_CLOSE_EVENT:
28 case CTRL_SHUTDOWN_EVENT:
29 console_ctrl_function();
36 int main(
int argc,
char* argv[]) {
42 std::cerr <<
"Usage: http_server <address> <port> <threads> <doc_root>\n";
43 std::cerr <<
" For IPv4, try:\n";
44 std::cerr <<
" http_server 0.0.0.0 80 1 .\n";
45 std::cerr <<
" For IPv6, try:\n";
46 std::cerr <<
" http_server 0::0 80 1 .\n";
51 std::size_t num_threads = boost::lexical_cast<std::size_t>(argv[3]);
56 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
61 }
catch (std::exception& e) {
62 std::cerr <<
"exception: " << e.what() <<
"\n";
67 #endif // defined(_WIN32)