]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/examples/http_server.cpp
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include "http_async_server.hpp"
9 #include "http_sync_server.hpp"
11 #include <beast/test/sig_wait.hpp>
12 #include <boost/program_options.hpp>
16 int main(int ac
, char const* av
[])
18 using namespace beast::http
;
19 namespace po
= boost::program_options
;
20 po::options_description
desc("Options");
23 ("root,r", po::value
<std::string
>()->default_value("."),
24 "Set the root directory for serving files")
25 ("port,p", po::value
<std::uint16_t>()->default_value(8080),
26 "Set the port number for the server")
27 ("ip", po::value
<std::string
>()->default_value("0.0.0.0"),
28 "Set the IP address to bind to, \"0.0.0.0\" for all")
29 ("threads,n", po::value
<std::size_t>()->default_value(4),
30 "Set the number of threads to use")
31 ("sync,s", "Launch a synchronous server")
34 po::store(po::parse_command_line(ac
, av
, desc
), vm
);
36 std::string root
= vm
["root"].as
<std::string
>();
38 std::uint16_t port
= vm
["port"].as
<std::uint16_t>();
40 std::string ip
= vm
["ip"].as
<std::string
>();
42 std::size_t threads
= vm
["threads"].as
<std::size_t>();
44 bool sync
= vm
.count("sync") > 0;
46 using endpoint_type
= boost::asio::ip::tcp::endpoint
;
47 using address_type
= boost::asio::ip::address
;
49 endpoint_type ep
{address_type::from_string(ip
), port
};
53 http_sync_server
server(ep
, root
);
54 beast::test::sig_wait();
58 http_async_server
server(ep
, threads
, root
);
59 beast::test::sig_wait();