generated from Sithas/conan_template
Initial commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include "sdk.h"
|
||||
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "RequestHandlers/BasicRequestHandler.h"
|
||||
#include "Listener.h"
|
||||
|
||||
namespace beast = boost::beast;
|
||||
namespace http = beast::http;
|
||||
namespace net = boost::asio;
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
using namespace uad;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 5)
|
||||
{
|
||||
std::cerr <<
|
||||
"Usage: http-server-async <address> <port> <doc_root> <threads>\n" <<
|
||||
"Example:\n" <<
|
||||
" http-server-async 0.0.0.0 8080 . 1\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auto const address = net::ip::make_address(argv[1]);
|
||||
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||
auto const doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
net::io_context ioc {threads};
|
||||
|
||||
std::make_shared<Listener>(
|
||||
ioc,
|
||||
tcp::endpoint {address, port},
|
||||
doc_root)->Run();
|
||||
|
||||
std::vector<std::thread> v;
|
||||
v.reserve(threads - 1);
|
||||
for (auto i = threads - 1; i > 0; --i)
|
||||
v.emplace_back(
|
||||
[&ioc]
|
||||
{
|
||||
ioc.run();
|
||||
});
|
||||
ioc.run();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user