diff options
Diffstat (limited to '')
-rw-r--r-- | server/main/server.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/server/main/server.cpp b/server/main/server.cpp index aef7d00..72034b1 100644 --- a/server/main/server.cpp +++ b/server/main/server.cpp @@ -4,19 +4,18 @@ // Distributed under the MIT License. #include "server.hpp" -#include "session.hpp" -#include "session_manager.hpp" -#include "settings.hpp" #include "../common/error.hpp" #include "../common/log.hpp" +#include "session.hpp" +#include "session_manager.hpp" +#include "settings.hpp" #include <boost/asio.hpp> #include <boost/system/error_code.hpp> #include <boost/system/system_error.hpp> #include <cstddef> - #include <exception> #include <thread> #include <vector> @@ -40,17 +39,12 @@ void configure_acceptor(boost::asio::ip::tcp::acceptor& acceptor, unsigned short } } -} +} // namespace -Server::Server(const Settings& settings) - : Server{settings.m_port, settings.m_threads} -{ } +Server::Server(const Settings& settings) : Server{settings.m_port, settings.m_threads} {} Server::Server(unsigned short port, std::size_t threads) - : m_numof_threads{threads} - , m_signals{m_io_context} - , m_acceptor{m_io_context} { - + : m_numof_threads{threads}, m_signals{m_io_context}, m_acceptor{m_io_context} { wait_for_signal(); configure_acceptor(m_acceptor, port); @@ -60,7 +54,7 @@ Server::Server(unsigned short port, std::size_t threads) void Server::run() { std::vector<std::thread> threads{m_numof_threads}; for (std::size_t i = 0; i < m_numof_threads; ++i) { - threads[i] = std::thread{[this] () { m_io_context.run(); }}; + threads[i] = std::thread{[this]() { m_io_context.run(); }}; } for (std::size_t i = 0; i < m_numof_threads; ++i) { @@ -73,9 +67,8 @@ void Server::wait_for_signal() { m_signals.add(SIGINT); m_signals.add(SIGTERM); - m_signals.async_wait([this] (const boost::system::error_code& ec, int signo) { - handle_signal(ec, signo); - }); + m_signals.async_wait( + [this](const boost::system::error_code& ec, int signo) { handle_signal(ec, signo); }); } catch (const boost::system::system_error& e) { throw Error{e.what()}; } @@ -98,10 +91,9 @@ void Server::handle_signal(const boost::system::error_code& ec, int signo) { void Server::accept() { const auto session = m_session_mgr.make_session(m_io_context); - m_acceptor.async_accept(session->socket(), - [session, this] (const boost::system::error_code& ec) { - handle_accept(session, ec); - }); + m_acceptor.async_accept( + session->socket(), + [session, this](const boost::system::error_code& ec) { handle_accept(session, ec); }); } void Server::handle_accept(SessionPtr session, const boost::system::error_code& ec) { @@ -114,4 +106,4 @@ void Server::handle_accept(SessionPtr session, const boost::system::error_code& accept(); } -} +} // namespace math::server |