libcutils: remove unused socket_set_receive_timeout().
Test: treehugger Change-Id: I834762fd83bdaa3b714c7531439bf9115a82e342
This commit is contained in:
parent
0bc3f6b124
commit
d91984a890
4 changed files with 0 additions and 65 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<char*>(&timeout_ms), sizeof(timeout_ms));
|
||||
}
|
||||
|
||||
ssize_t socket_send_buffers(cutils_socket_t sock,
|
||||
const cutils_socket_buffer_t* buffers,
|
||||
size_t num_buffers) {
|
||||
|
|
Loading…
Reference in a new issue