diff --git a/test/websocket/websocket_async_echo_peer.hpp b/test/websocket/websocket_async_echo_peer.hpp index 7b238098..f03908cb 100644 --- a/test/websocket/websocket_async_echo_peer.hpp +++ b/test/websocket/websocket_async_echo_peer.hpp @@ -43,6 +43,7 @@ public: using socket_type = boost::asio::ip::tcp::socket; private: + bool log_ = false; boost::asio::io_service ios_; socket_type sock_; boost::asio::ip::tcp::acceptor acceptor_; @@ -72,7 +73,7 @@ public: } else { - Peer{std::move(sock_), ep}; + Peer{log_, std::move(sock_), ep}; } thread_.reserve(threads); for(std::size_t i = 0; i < threads; ++i) @@ -100,6 +101,7 @@ private: { struct data { + bool log; int state = 0; boost::optional ep; websocket::stream ws; @@ -107,8 +109,9 @@ private: beast::streambuf sb; int id; - data(socket_type&& sock_) - : ws(std::move(sock_)) + data(bool log_, socket_type&& sock_) + : log(log_) + , ws(std::move(sock_)) , id([] { static int n = 0; @@ -117,9 +120,10 @@ private: { } - data(socket_type&& sock_, + data(bool log_, socket_type&& sock_, endpoint_type const& ep_) - : ep(ep_) + : log(log_) + , ep(ep_) , ws(std::move(sock_)) , id([] { @@ -157,8 +161,8 @@ private: template explicit - Peer(socket_type&& sock, Args&&... args) - : d_(std::make_shared( + Peer(bool log, socket_type&& sock, Args&&... args) + : d_(std::make_shared(log, std::forward(sock), std::forward(args)...)) { @@ -186,7 +190,7 @@ private: void operator()(error_code ec) { auto& d = *d_; - switch(d_->state) + switch(d.state) { // did accept case 0: @@ -232,17 +236,22 @@ private: void fail(error_code ec, std::string what) { - if(ec != websocket::error::closed) - std::cerr << "#" << d_->id << " " << - what << ": " << ec.message() << std::endl; + auto& d = *d_; + if(d.log) + { + if(ec != websocket::error::closed) + std::cerr << "#" << d_->id << " " << + what << ": " << ec.message() << std::endl; + } } }; void fail(error_code ec, std::string what) { - std::cerr << - what << ": " << ec.message() << std::endl; + if(log_) + std::cerr << what << ": " << + ec.message() << std::endl; } void @@ -265,7 +274,7 @@ private: acceptor_.async_accept(sock_, std::bind(&async_echo_peer::on_accept, this, beast::asio::placeholders::error)); - Peer{std::move(sock)}; + Peer{false, std::move(sock)}; } }; diff --git a/test/websocket/websocket_sync_echo_peer.hpp b/test/websocket/websocket_sync_echo_peer.hpp index 084fcf75..03bb484e 100644 --- a/test/websocket/websocket_sync_echo_peer.hpp +++ b/test/websocket/websocket_sync_echo_peer.hpp @@ -42,6 +42,7 @@ public: using socket_type = boost::asio::ip::tcp::socket; private: + bool log_ = false; boost::asio::io_service ios_; socket_type sock_; boost::asio::ip::tcp::acceptor acceptor_; @@ -83,23 +84,22 @@ public: } private: - static void fail(error_code ec, std::string what) { - std::cerr << - what << ": " << ec.message() << std::endl; + if(log_) + std::cerr << + what << ": " << ec.message() << std::endl; } - static void fail(int id, error_code ec, std::string what) { - std::cerr << "#" << std::to_string(id) << " " << - what << ": " << ec.message() << std::endl; + if(log_) + std::cerr << "#" << std::to_string(id) << " " << + what << ": " << ec.message() << std::endl; } - static void maybe_throw(error_code ec, std::string what) {