From d91984a890aabf0fcad333100feba87951891c69 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 8 Nov 2019 15:21:39 -0800 Subject: [PATCH] libcutils: remove unused socket_set_receive_timeout(). Test: treehugger Change-Id: I834762fd83bdaa3b714c7531439bf9115a82e342 --- libcutils/include/cutils/sockets.h | 8 ------ libcutils/sockets_test.cpp | 45 ------------------------------ libcutils/sockets_unix.cpp | 7 ----- libcutils/sockets_windows.cpp | 5 ---- 4 files changed, 65 deletions(-) diff --git a/libcutils/include/cutils/sockets.h b/libcutils/include/cutils/sockets.h index 285f15083..be21a8f7f 100644 --- a/libcutils/include/cutils/sockets.h +++ b/libcutils/include/cutils/sockets.h @@ -102,14 +102,6 @@ cutils_socket_t socket_inaddr_any_server(int port, int type); */ int socket_close(cutils_socket_t sock); -/* - * Sets socket receive timeout using SO_RCVTIMEO. Setting |timeout_ms| to 0 - * disables receive timeouts. - * - * Return 0 on success. - */ -int socket_set_receive_timeout(cutils_socket_t sock, int timeout_ms); - /* * Returns the local port the socket is bound to or -1 on error. */ diff --git a/libcutils/sockets_test.cpp b/libcutils/sockets_test.cpp index b762ac15e..1fa40bc6a 100644 --- a/libcutils/sockets_test.cpp +++ b/libcutils/sockets_test.cpp @@ -73,25 +73,6 @@ static void TestConnectedSockets(cutils_socket_t server, cutils_socket_t client, EXPECT_EQ(0, socket_close(client)); } -// Tests receive timeout. The timing verification logic must be very coarse to -// make sure different systems can all pass these tests. -void TestReceiveTimeout(cutils_socket_t sock) { - time_t start_time; - char buffer[32]; - - // Make sure a 20ms timeout completes in 1 second or less. - EXPECT_EQ(0, socket_set_receive_timeout(sock, 20)); - start_time = time(nullptr); - EXPECT_EQ(-1, recv(sock, buffer, sizeof(buffer), 0)); - EXPECT_LE(difftime(time(nullptr), start_time), 1.0); - - // Make sure a 1250ms timeout takes 1 second or more. - EXPECT_EQ(0, socket_set_receive_timeout(sock, 1250)); - start_time = time(nullptr); - EXPECT_EQ(-1, recv(sock, buffer, sizeof(buffer), 0)); - EXPECT_LE(1.0, difftime(time(nullptr), start_time)); -} - // Tests socket_get_local_port(). TEST(SocketsTest, TestGetLocalPort) { cutils_socket_t server; @@ -157,32 +138,6 @@ TEST(SocketsTest, TestIpv6TcpLoopback) { TestConnectedSockets(handler, client, SOCK_STREAM); } -// Tests setting a receive timeout for UDP sockets. -TEST(SocketsTest, TestUdpReceiveTimeout) { - cutils_socket_t sock = socket_inaddr_any_server(0, SOCK_DGRAM); - ASSERT_NE(INVALID_SOCKET, sock); - - TestReceiveTimeout(sock); - - EXPECT_EQ(0, socket_close(sock)); -} - -// Tests setting a receive timeout for TCP sockets. -TEST(SocketsTest, TestTcpReceiveTimeout) { - cutils_socket_t server = socket_inaddr_any_server(0, SOCK_STREAM); - ASSERT_NE(INVALID_SOCKET, server); - - cutils_socket_t client = socket_network_client( - "localhost", socket_get_local_port(server), SOCK_STREAM); - cutils_socket_t handler = accept(server, nullptr, nullptr); - EXPECT_EQ(0, socket_close(server)); - - TestReceiveTimeout(handler); - - EXPECT_EQ(0, socket_close(client)); - EXPECT_EQ(0, socket_close(handler)); -} - // Tests socket_send_buffers() failure. TEST(SocketsTest, TestSocketSendBuffersFailure) { EXPECT_EQ(-1, socket_send_buffers(INVALID_SOCKET, nullptr, 0)); diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp index 6acdcd89b..84663e675 100644 --- a/libcutils/sockets_unix.cpp +++ b/libcutils/sockets_unix.cpp @@ -31,13 +31,6 @@ int socket_close(int sock) { return close(sock); } -int socket_set_receive_timeout(cutils_socket_t sock, int timeout_ms) { - timeval tv; - tv.tv_sec = timeout_ms / 1000; - tv.tv_usec = (timeout_ms % 1000) * 1000; - return setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); -} - ssize_t socket_send_buffers(cutils_socket_t sock, const cutils_socket_buffer_t* buffers, size_t num_buffers) { diff --git a/libcutils/sockets_windows.cpp b/libcutils/sockets_windows.cpp index df1471220..4adb79691 100644 --- a/libcutils/sockets_windows.cpp +++ b/libcutils/sockets_windows.cpp @@ -54,11 +54,6 @@ int socket_close(cutils_socket_t sock) { return closesocket(sock); } -int socket_set_receive_timeout(cutils_socket_t sock, int timeout_ms) { - return setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, - reinterpret_cast(&timeout_ms), sizeof(timeout_ms)); -} - ssize_t socket_send_buffers(cutils_socket_t sock, const cutils_socket_buffer_t* buffers, size_t num_buffers) {