00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012 #include <string>
00013 #include <asio.hpp>
00014 #include <boost/bind.hpp>
00015 #include <boost/function.hpp>
00016 #include "server.hpp"
00017
00018 #if defined(_WIN32)
00019
00020 boost::function0<void> console_ctrl_function;
00021
00022 BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
00023 {
00024 switch (ctrl_type)
00025 {
00026 case CTRL_C_EVENT:
00027 case CTRL_BREAK_EVENT:
00028 case CTRL_CLOSE_EVENT:
00029 case CTRL_SHUTDOWN_EVENT:
00030 console_ctrl_function();
00031 return TRUE;
00032 default:
00033 return FALSE;
00034 }
00035 }
00036
00037 int main(int argc, char* argv[])
00038 {
00039 try
00040 {
00041
00042 if (argc != 4)
00043 {
00044 std::cerr << "Usage: http_server <address> <port> <doc_root>\n";
00045 std::cerr << " For IPv4, try:\n";
00046 std::cerr << " http_server 0.0.0.0 80 .\n";
00047 std::cerr << " For IPv6, try:\n";
00048 std::cerr << " http_server 0::0 80 .\n";
00049 return 1;
00050 }
00051
00052
00053 http::server::server s(argv[1], argv[2], argv[3]);
00054
00055
00056 console_ctrl_function = boost::bind(&http::server::server::stop, &s);
00057 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
00058
00059
00060 s.run();
00061 }
00062 catch (std::exception& e)
00063 {
00064 std::cerr << "exception: " << e.what() << "\n";
00065 }
00066
00067 return 0;
00068 }
00069
00070 #endif // defined(_WIN32)