From 2847a885252715e347d1374b951221efe15d949c Mon Sep 17 00:00:00 2001 From: taynpg Date: Wed, 5 Mar 2025 10:20:56 +0800 Subject: [PATCH] =?UTF-8?q?1.=E9=85=8D=E7=BD=AE=E9=BB=98=E8=AE=A4=E4=BD=BF?= =?UTF-8?q?=E7=94=A8v3=E3=80=822.asio=E4=B8=AD=E6=96=87=E8=BD=ACu8?= =?UTF-8?q?=E3=80=823.com*hpp=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AAtrim?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.cxx | 17 +++++++++++------ server.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) 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_;