]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/examples/http_server.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / examples / http_server.cpp
1 //
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7
8 #include "http_async_server.hpp"
9 #include "http_sync_server.hpp"
10
11 #include <beast/test/sig_wait.hpp>
12 #include <boost/program_options.hpp>
13
14 #include <iostream>
15
16 int main(int ac, char const* av[])
17 {
18 using namespace beast::http;
19 namespace po = boost::program_options;
20 po::options_description desc("Options");
21
22 desc.add_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")
32 ;
33 po::variables_map vm;
34 po::store(po::parse_command_line(ac, av, desc), vm);
35
36 std::string root = vm["root"].as<std::string>();
37
38 std::uint16_t port = vm["port"].as<std::uint16_t>();
39
40 std::string ip = vm["ip"].as<std::string>();
41
42 std::size_t threads = vm["threads"].as<std::size_t>();
43
44 bool sync = vm.count("sync") > 0;
45
46 using endpoint_type = boost::asio::ip::tcp::endpoint;
47 using address_type = boost::asio::ip::address;
48
49 endpoint_type ep{address_type::from_string(ip), port};
50
51 if(sync)
52 {
53 http_sync_server server(ep, root);
54 beast::test::sig_wait();
55 }
56 else
57 {
58 http_async_server server(ep, threads, root);
59 beast::test::sig_wait();
60 }
61 }