summaryrefslogtreecommitdiffhomepage
path: root/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server.cpp')
-rw-r--r--server.cpp56
1 files changed, 54 insertions, 2 deletions
diff --git a/server.cpp b/server.cpp
index 2ad9bcd..bbe7223 100644
--- a/server.cpp
+++ b/server.cpp
@@ -1,10 +1,62 @@
+#include <boost/beast/core.hpp>
+#include <boost/beast/http.hpp>
+#include <boost/beast/version.hpp>
+#include <boost/beast/ssl.hpp>
+#include <boost/asio/dispatch.hpp>
+#include <boost/asio/strand.hpp>
+#include <boost/config.hpp>
+
+#include <thread>
+#include <vector>
+
#include "server.h"
#include "http.h"
#include "https.h"
+namespace beast = boost::beast; // from <boost/beast.hpp>
+namespace http = beast::http; // from <boost/beast/http.hpp>
+namespace net = boost::asio; // from <boost/asio.hpp>
+namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
+using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
+
+Server::Server(Config& config, boost::asio::io_context& ioc): m_config(config), m_ioc(ioc)
+{
+}
+
+Server::~Server()
+{
+}
+
int server(Config& config)
{
- //return HTTP::server(config);
- return HTTPS::server(config);
+ auto const threads = std::max<int>(1, config.Threads());
+
+ boost::asio::io_context ioc{threads};
+
+ std::vector<std::shared_ptr<Server>> servers;
+
+ const auto& sockets {config.Sockets()};
+ for (const auto& socket: sockets) {
+ if (socket.protocol == SocketProtocol::HTTP) {
+ servers.push_back(std::make_shared<HTTP::Server>(config, ioc, socket));
+ } else {
+ servers.push_back(std::make_shared<HTTPS::Server>(config, ioc, socket));
+ }
+ servers.back()->start();
+ }
+
+ // Run the I/O service on the requested number of threads
+ 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;
}
+