summaryrefslogtreecommitdiffhomepage
path: root/https.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'https.cpp')
-rw-r--r--https.cpp57
1 files changed, 23 insertions, 34 deletions
diff --git a/https.cpp b/https.cpp
index 0c3b97b..b4e77f9 100644
--- a/https.cpp
+++ b/https.cpp
@@ -515,42 +515,31 @@ private:
namespace HTTPS {
-int server(Config& config)
+Server::Server(Config& config, boost::asio::io_context& ioc, const Socket& socket): ::Server(config, ioc), m_socket(socket)
{
- // TODO: Config
- auto const address = net::ip::make_address(config.Sockets()[0].address);
- auto const port = static_cast<unsigned short>(std::atoi(config.Sockets()[0].port.data()));
- auto const doc_root = std::make_shared<std::string>(config.Sites()[0].paths[0].params.at("target"));
- auto const threads = std::max<int>(1, config.Threads());
-
- // The io_context is required for all I/O
- net::io_context ioc{threads};
-
- // The SSL context is required, and holds certificates
- ssl::context ctx{ssl::context::tlsv13};
-
- // This holds the self-signed certificate used by the server
- load_server_certificate(ctx, config.Sockets()[0].cert_path, config.Sockets()[0].key_path); // TODO: config
-
- // Create and launch a listening port
- std::make_shared<listener>(
- ioc,
- ctx,
- tcp::endpoint{address, port},
- doc_root)->run();
-
- // 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();
+ // This holds the self-signed certificate used by the server
+ load_server_certificate(m_ctx, m_socket.cert_path, m_socket.key_path);
+}
+
+Server::~Server()
+{
+}
- return EXIT_SUCCESS;
+int Server::start()
+{
+ // TODO: Config
+ auto const address = net::ip::make_address(m_socket.address);
+ auto const port = static_cast<unsigned short>(std::atoi(m_socket.port.data()));
+ auto const doc_root = std::make_shared<std::string>(m_config.Sites()[0].paths[0].params.at("target"));
+
+ // Create and launch a listening port
+ std::make_shared<listener>(
+ m_ioc,
+ m_ctx,
+ tcp::endpoint{address, port},
+ doc_root)->run();
+
+ return EXIT_SUCCESS;
}
} // namespace HTTPS