aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server/main
diff options
context:
space:
mode:
Diffstat (limited to 'server/main')
-rw-r--r--server/main/server.cpp34
-rw-r--r--server/main/server.hpp2
-rw-r--r--server/main/session.cpp30
-rw-r--r--server/main/session.hpp3
-rw-r--r--server/main/session_manager.cpp4
-rw-r--r--server/main/session_manager.hpp4
-rw-r--r--server/main/settings.hpp35
7 files changed, 48 insertions, 64 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
diff --git a/server/main/server.hpp b/server/main/server.hpp
index 6233bff..456f075 100644
--- a/server/main/server.hpp
+++ b/server/main/server.hpp
@@ -38,4 +38,4 @@ private:
SessionManager m_session_mgr;
};
-}
+} // namespace math::server
diff --git a/server/main/session.cpp b/server/main/session.cpp
index 900e5b4..3917514 100644
--- a/server/main/session.cpp
+++ b/server/main/session.cpp
@@ -4,11 +4,11 @@
// Distributed under the MIT License.
#include "session.hpp"
-#include "session_manager.hpp"
#include "../common/error.hpp"
#include "../common/log.hpp"
#include "../parser/parser.hpp"
+#include "session_manager.hpp"
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
@@ -16,7 +16,6 @@
#include <boost/system/system_error.hpp>
#include <cstddef>
-
#include <exception>
#include <string>
#include <utility>
@@ -38,11 +37,10 @@ std::string calc_reply(const std::string& input) {
return reply;
}
-}
+} // namespace
Session::Session(SessionManager& mgr, boost::asio::io_context& io_context)
- : m_session_mgr{mgr}, m_strand{io_context}, m_socket{io_context}
-{ }
+ : m_session_mgr{mgr}, m_strand{io_context}, m_socket{io_context} {}
boost::asio::ip::tcp::socket& Session::socket() {
return m_socket;
@@ -69,10 +67,12 @@ void Session::read() {
const auto self = shared_from_this();
// Stop at LF
- boost::asio::async_read_until(m_socket, m_buffer, '\n', boost::asio::bind_executor(m_strand,
- [this, self] (const boost::system::error_code& ec, std::size_t bytes) {
- handle_read(ec, bytes);
- }));
+ boost::asio::async_read_until(
+ m_socket, m_buffer, '\n',
+ boost::asio::bind_executor(
+ m_strand, [this, self](const boost::system::error_code& ec, std::size_t bytes) {
+ handle_read(ec, bytes);
+ }));
}
void Session::handle_read(const boost::system::error_code& ec, std::size_t bytes) {
@@ -99,10 +99,12 @@ void Session::write(const std::string& output) {
// Include CR (so that Windows' telnet client works)
os << output << "\r\n";
- boost::asio::async_write(m_socket, m_buffer, boost::asio::bind_executor(m_strand,
- [this, self] (const boost::system::error_code& ec, std::size_t bytes) {
- handle_write(ec, bytes);
- }));
+ boost::asio::async_write(
+ m_socket, m_buffer,
+ boost::asio::bind_executor(
+ m_strand, [this, self](const boost::system::error_code& ec, std::size_t bytes) {
+ handle_write(ec, bytes);
+ }));
}
void Session::handle_write(const boost::system::error_code& ec, std::size_t bytes) {
@@ -115,4 +117,4 @@ void Session::handle_write(const boost::system::error_code& ec, std::size_t byte
read();
}
-}
+} // namespace math::server
diff --git a/server/main/session.hpp b/server/main/session.hpp
index 31be327..2ab8f26 100644
--- a/server/main/session.hpp
+++ b/server/main/session.hpp
@@ -9,7 +9,6 @@
#include <boost/system/error_code.hpp>
#include <cstddef>
-
#include <memory>
#include <string>
@@ -44,4 +43,4 @@ private:
boost::asio::streambuf m_buffer;
};
-}
+} // namespace math::server
diff --git a/server/main/session_manager.cpp b/server/main/session_manager.cpp
index d73e998..753750d 100644
--- a/server/main/session_manager.cpp
+++ b/server/main/session_manager.cpp
@@ -3,10 +3,10 @@
// For details, see https://github.com/egor-tensin/math-server.
// Distributed under the MIT License.
-#include "session.hpp"
#include "session_manager.hpp"
#include "../common/log.hpp"
+#include "session.hpp"
#include <memory>
#include <mutex>
@@ -40,4 +40,4 @@ void SessionManager::stop_all() {
m_sessions.clear();
}
-}
+} // namespace math::server
diff --git a/server/main/session_manager.hpp b/server/main/session_manager.hpp
index 66b8d67..762bfc5 100644
--- a/server/main/session_manager.hpp
+++ b/server/main/session_manager.hpp
@@ -7,8 +7,8 @@
#include <boost/asio.hpp>
-#include <mutex>
#include <memory>
+#include <mutex>
#include <unordered_set>
namespace math::server {
@@ -32,4 +32,4 @@ private:
std::unordered_set<SessionPtr> m_sessions;
};
-}
+} // namespace math::server
diff --git a/server/main/settings.hpp b/server/main/settings.hpp
index a334fe7..11982da 100644
--- a/server/main/settings.hpp
+++ b/server/main/settings.hpp
@@ -9,7 +9,6 @@
#include <boost/program_options.hpp>
#include <cstddef>
-
#include <exception>
#include <iostream>
#include <string>
@@ -33,29 +32,23 @@ struct Settings {
class SettingsParser {
public:
- explicit SettingsParser(const std::string& argv0)
- : m_prog_name{extract_filename(argv0)}
- {
+ explicit SettingsParser(const std::string& argv0) : m_prog_name{extract_filename(argv0)} {
m_visible.add_options()("help,h", "show this message and exit");
- m_visible.add_options()(
- "port,p",
- boost::program_options::value(&m_settings.m_port)->default_value(Settings::DEFAULT_PORT),
- "server port number");
- m_visible.add_options()(
- "threads,n",
- boost::program_options::value(&m_settings.m_threads)->default_value(Settings::default_threads()),
- "number of threads");
+ m_visible.add_options()("port,p",
+ boost::program_options::value(&m_settings.m_port)
+ ->default_value(Settings::DEFAULT_PORT),
+ "server port number");
+ m_visible.add_options()("threads,n",
+ boost::program_options::value(&m_settings.m_threads)
+ ->default_value(Settings::default_threads()),
+ "number of threads");
}
- static const char* get_short_description() {
- return "[-h|--help] [-p|--port] [-n|--threads]";
- }
+ static const char* get_short_description() { return "[-h|--help] [-p|--port] [-n|--threads]"; }
Settings parse(int argc, char* argv[]) {
boost::program_options::store(
- boost::program_options::command_line_parser{argc, argv}
- .options(m_visible)
- .run(),
+ boost::program_options::command_line_parser{argc, argv}.options(m_visible).run(),
m_settings.m_vm);
if (m_settings.exit_with_usage()) {
return m_settings;
@@ -64,9 +57,7 @@ public:
return m_settings;
}
- void usage() const {
- std::cout << *this;
- }
+ void usage() const { std::cout << *this; }
void usage_error(const std::exception& e) const {
std::cerr << "usage error: " << e.what() << '\n';
@@ -91,4 +82,4 @@ private:
}
};
-}
+} // namespace math::server