From: Francis Dupont Date: Fri, 19 Feb 2021 17:41:51 +0000 (+0100) Subject: [#1661] Revamped isConnection{Alive,Closed} X-Git-Tag: Kea-1.9.6~119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2e2a95e53e990c6a4d656f8415c6541ef9d46d5;p=thirdparty%2Fkea.git [#1661] Revamped isConnection{Alive,Closed} --- diff --git a/src/lib/http/tests/tls_server_unittests.cc b/src/lib/http/tests/tls_server_unittests.cc index 0a811f3636..1808ef7cf7 100644 --- a/src/lib/http/tests/tls_server_unittests.cc +++ b/src/lib/http/tests/tls_server_unittests.cc @@ -579,12 +579,9 @@ public: stream_.lowest_layer().non_blocking(true); // We need to provide a buffer for a call to read. - int fd = stream_.lowest_layer().native_handle(); char data[2]; - int err = 0; - if (recv(fd, data, sizeof(data), MSG_PEEK) < 0) { - err = errno; - } + boost::system::error_code ec; + boost::asio::read(stream_, boost::asio::buffer(data, sizeof(data)), ec); // Revert the original non_blocking flag on the socket. stream_.lowest_layer().non_blocking(non_blocking_orig); @@ -595,7 +592,8 @@ public: // implementations in some situations. Any other error code indicates a // problem with the connection so we assume that the connection has been // closed. - return ((err == 0) || (err == EAGAIN) || (err == EWOULDBLOCK)); + return (!ec || (ec.value() == boost::asio::error::try_again) || + (ec.value() == boost::asio::error::would_block)); } /// @brief Checks if the TCP connection is already closed. @@ -614,19 +612,17 @@ public: stream_.lowest_layer().non_blocking(false); // We need to provide a buffer for a call to read. - int fd = stream_.lowest_layer().native_handle(); char data[2]; - int err = 0; - int cc = recv(fd, data, sizeof(data), MSG_PEEK); - if (cc < 0) { - err = errno; - } + boost::system::error_code ec; + boost::asio::read(stream_, boost::asio::buffer(data, sizeof(data)), ec); // Revert the original non_blocking flag on the socket. stream_.lowest_layer().non_blocking(non_blocking_orig); - // If the connection is closed we'd typically get eof status code. - return ((cc == 0) || (err == ECONNRESET)); + // If the connection is closed we'd typically get eof or + // stream_truncated status code. + return ((ec.value() == boost::asio::error::eof) || + (ec.value() == boost::asio::ssl::error::stream_truncated)); } /// @brief Close connection.