]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1661] Revamped isConnection{Alive,Closed}
authorFrancis Dupont <fdupont@isc.org>
Fri, 19 Feb 2021 17:41:51 +0000 (18:41 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 24 Mar 2021 08:09:02 +0000 (09:09 +0100)
src/lib/http/tests/tls_server_unittests.cc

index 0a811f36369a3ac215d6a4853b2db7c28f681f2f..1808ef7cf760138bbd3f5f0f933f6b40a56c322e 100644 (file)
@@ -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.