From f4c65a5ba69e979a30a5f4e833c576aa7963170b Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 19 Jun 2017 19:42:06 -0700 Subject: [PATCH] Squelch harmless not_connected errors --- CHANGELOG.md | 1 + example/http-client-ssl/http_client_ssl.cpp | 2 +- example/http-client/http_client.cpp | 6 +++++- example/http-crawl/http_crawl.cpp | 4 ++-- example/server-framework/http_async_port.hpp | 6 +++++- example/server-framework/http_sync_port.hpp | 8 ++++---- example/server-framework/https_ports.hpp | 2 +- example/server-framework/multi_port.hpp | 5 +++-- 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7d61604..b15b7147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Version 62: * Clear the error faster * Avoid explicit operator bool for error * Add http::is_fields trait +* Squelch harmless not_connected errors API Changes: diff --git a/example/http-client-ssl/http_client_ssl.cpp b/example/http-client-ssl/http_client_ssl.cpp index 59bcb83d..65b089f3 100644 --- a/example/http-client-ssl/http_client_ssl.cpp +++ b/example/http-client-ssl/http_client_ssl.cpp @@ -88,7 +88,7 @@ int main() // Shut down SSL on the stream stream.shutdown(ec); if(ec && ec != boost::asio::error::eof) - fail("ssl shutdown ", ec); + fail("ssl_shutdown ", ec); // If we get here then the connection is closed gracefully return EXIT_SUCCESS; diff --git a/example/http-client/http_client.cpp b/example/http-client/http_client.cpp index fe405462..9e0b50a9 100644 --- a/example/http-client/http_client.cpp +++ b/example/http-client/http_client.cpp @@ -78,7 +78,11 @@ int main() // Gracefully close the socket sock.shutdown(tcp::socket::shutdown_both, ec); - if(ec) + + // not_connected happens sometimes + // so don't bother reporting it. + // + if(ec && ec != beast::errc::not_connected) return fail("shutdown", ec); // If we get here then the connection is closed gracefully diff --git a/example/http-crawl/http_crawl.cpp b/example/http-crawl/http_crawl.cpp index af74cde4..3d96626c 100644 --- a/example/http-crawl/http_crawl.cpp +++ b/example/http-crawl/http_crawl.cpp @@ -100,7 +100,7 @@ main(int, char const*[]) // "half-close" here to shut down our end. // sock.shutdown(tcp::socket::shutdown_send, ec); - if(ec) + if(ec && ec != beast::errc::not_connected) return fail("shutdown", ec); } if(ec) @@ -134,7 +134,7 @@ main(int, char const*[]) // Now we do the other half of the close, // which is to shut down the receiver. sock.shutdown(tcp::socket::shutdown_receive, ec); - if(ec) + if(ec && ec != beast::errc::not_connected) return fail("shutdown", ec); std::cout << res << std::endl; diff --git a/example/server-framework/http_async_port.hpp b/example/server-framework/http_async_port.hpp index 12d224c5..74d32706 100644 --- a/example/server-framework/http_async_port.hpp +++ b/example/server-framework/http_async_port.hpp @@ -560,7 +560,11 @@ private: { error_code ec; stream().shutdown(socket_type::shutdown_both, ec); - if(ec) + + // not_connected happens under normal + // circumstances so don't bother reporting it. + // + if(ec && ec != beast::errc::not_connected) return this->fail("shutdown", ec); } }; diff --git a/example/server-framework/http_sync_port.hpp b/example/server-framework/http_sync_port.hpp index c80e5775..973cb03d 100644 --- a/example/server-framework/http_sync_port.hpp +++ b/example/server-framework/http_sync_port.hpp @@ -198,7 +198,7 @@ private: { // Give the derived class a chance to do stuff impl().do_shutdown(ec); - if(ec) + if(ec && ec != beast::errc::not_connected) return fail("shutdown", ec); return; } @@ -229,7 +229,7 @@ private: { // Give the derived class a chance to do stuff impl().do_shutdown(ec); - if(ec) + if(ec && ec != beast::errc::not_connected) return fail("shutdown", ec); return; } @@ -273,7 +273,7 @@ private: { // Give the derived class a chance to do stuff impl().do_shutdown(ec); - if(ec) + if(ec && ec != beast::errc::not_connected) return fail("shutdown", ec); return; } @@ -293,7 +293,7 @@ private: if(ec == beast::http::error::end_of_stream) { // Give the derived class a chance to do stuff - impl().do_shutdown(ec); + if(ec && ec != beast::errc::not_connected) if(ec) return fail("shutdown", ec); return; diff --git a/example/server-framework/https_ports.hpp b/example/server-framework/https_ports.hpp index c00b6851..2d260d4d 100644 --- a/example/server-framework/https_ports.hpp +++ b/example/server-framework/https_ports.hpp @@ -93,7 +93,7 @@ private: // stream().shutdown(ec); if(ec) - return this->fail("shutdown", ec); + return this->fail("ssl_shutdown", ec); } }; diff --git a/example/server-framework/multi_port.hpp b/example/server-framework/multi_port.hpp index 7e5dca60..dca77ec4 100644 --- a/example/server-framework/multi_port.hpp +++ b/example/server-framework/multi_port.hpp @@ -177,9 +177,10 @@ private: socket_type::shutdown_both, ec); - // Report failure if any + // not_connected happens under normal + // circumstances so don't bother reporting it. // - if(ec) + if(ec && ec != beast::errc::not_connected) return this->fail("shutdown", ec); } };