]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp03/http/server4/main.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / example / cpp03 / http / server4 / main.cpp
1 //
2 // main.cpp
3 // ~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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
33 boost::asio::io_context io_context;
34
35 // Launch the initial server coroutine.
36 http::server4::server(io_context, argv[1], argv[2],
37 http::server4::file_handler(argv[3]))();
38
39 // Wait for signals indicating time to shut down.
40 boost::asio::signal_set signals(io_context);
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(
47 &boost::asio::io_context::stop, &io_context));
48
49 // Run the server.
50 io_context.run();
51 }
52 catch (std::exception& e)
53 {
54 std::cerr << "exception: " << e.what() << "\n";
55 }
56
57 return 0;
58 }