diff --git a/server.cxx b/server.cxx index ef96332..19d38de 100644 --- a/server.cxx +++ b/server.cxx @@ -14,6 +14,15 @@ Server::~Server() } } +void Server::print_exception(const std::exception& e) +{ +#ifdef _WIN32 + std::cerr << ansi_to_u8(e.what()) << '\n'; +#else + std::cerr << e.what() << '\n'; +#endif +} + void Server::start() { asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port_); @@ -24,11 +33,7 @@ void Server::start() acceptor_.listen(); do_accept(); } catch (const std::exception& e) { -#ifdef _WIN32 - std::cerr << ansi_to_u8(e.what()) << '\n'; -#else - std::cerr << e.what() << '\n'; -#endif + print_exception(e); } } @@ -159,4 +164,4 @@ bool Server::send_frame(const std::shared_ptr& socket, Fr delete[] send_data; return send_len == len; -} +} \ No newline at end of file diff --git a/server.h b/server.h index efbe72a..0fddffa 100644 --- a/server.h +++ b/server.h @@ -34,6 +34,7 @@ private: std::string post_data(const std::string& data); bool send_frame(const std::shared_ptr& socket, FrameData& data); + void print_exception(const std::exception& e); private: asio::io_context& io_context_;