]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // main.cpp | |
3 | // ~~~~~~~~ | |
4 | // | |
b32b8144 | 5 | // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
9 | // | |
10 | ||
11 | #include <iostream> | |
12 | #include <boost/asio.hpp> | |
13 | #include <boost/bind.hpp> | |
14 | #include <signal.h> | |
15 | #include "server.hpp" | |
16 | #include "file_handler.hpp" | |
17 | ||
18 | int main(int argc, char* argv[]) | |
19 | { | |
20 | try | |
21 | { | |
22 | // Check command line arguments. | |
23 | if (argc != 4) | |
24 | { | |
25 | std::cerr << "Usage: http_server <address> <port> <doc_root>\n"; | |
26 | std::cerr << " For IPv4, try:\n"; | |
27 | std::cerr << " receiver 0.0.0.0 80 .\n"; | |
28 | std::cerr << " For IPv6, try:\n"; | |
29 | std::cerr << " receiver 0::0 80 .\n"; | |
30 | return 1; | |
31 | } | |
32 | ||
b32b8144 | 33 | boost::asio::io_context io_context; |
7c673cae FG |
34 | |
35 | // Launch the initial server coroutine. | |
b32b8144 | 36 | http::server4::server(io_context, argv[1], argv[2], |
7c673cae FG |
37 | http::server4::file_handler(argv[3]))(); |
38 | ||
39 | // Wait for signals indicating time to shut down. | |
b32b8144 | 40 | boost::asio::signal_set signals(io_context); |
7c673cae FG |
41 | signals.add(SIGINT); |
42 | signals.add(SIGTERM); | |
43 | #if defined(SIGQUIT) | |
44 | signals.add(SIGQUIT); | |
45 | #endif // defined(SIGQUIT) | |
46 | signals.async_wait(boost::bind( | |
b32b8144 | 47 | &boost::asio::io_context::stop, &io_context)); |
7c673cae FG |
48 | |
49 | // Run the server. | |
b32b8144 | 50 | io_context.run(); |
7c673cae FG |
51 | } |
52 | catch (std::exception& e) | |
53 | { | |
54 | std::cerr << "exception: " << e.what() << "\n"; | |
55 | } | |
56 | ||
57 | return 0; | |
58 | } |