From 9ea77eb8bc4887b0c6286d507551848ae580052e Mon Sep 17 00:00:00 2001 From: Bruno Dal Bo Date: Wed, 3 Jan 2024 11:48:50 -0800 Subject: [PATCH] Allow infinite timeout in helpers PiperOrigin-RevId: 595462226 --- test/util/socket_util.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/util/socket_util.cc b/test/util/socket_util.cc index d151c557a..af241082d 100644 --- a/test/util/socket_util.cc +++ b/test/util/socket_util.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -766,11 +767,11 @@ PosixErrorOr SendMsg(int sock, msghdr* msg, char buf[], int buf_size) { PosixErrorOr RecvTimeout(int sock, char buf[], int buf_size, int timeout) { fd_set rfd; struct timeval to = {.tv_sec = timeout, .tv_usec = 0}; + struct timeval* to_ptr = timeout < 0 ? nullptr : &to; FD_ZERO(&rfd); FD_SET(sock, &rfd); - int ret; - RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, &to)); + RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, to_ptr)); RETURN_ERROR_IF_SYSCALL_FAIL( ret = RetryEINTR(recv)(sock, buf, buf_size, MSG_DONTWAIT)); return ret; @@ -779,11 +780,12 @@ PosixErrorOr RecvTimeout(int sock, char buf[], int buf_size, int timeout) { PosixErrorOr RecvMsgTimeout(int sock, struct msghdr* msg, int timeout) { fd_set rfd; struct timeval to = {.tv_sec = timeout, .tv_usec = 0}; + struct timeval* to_ptr = timeout < 0 ? nullptr : &to; FD_ZERO(&rfd); FD_SET(sock, &rfd); int ret; - RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, &to)); + RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, to_ptr)); RETURN_ERROR_IF_SYSCALL_FAIL( ret = RetryEINTR(recvmsg)(sock, msg, MSG_DONTWAIT)); return ret;