diff options
author | Zach Koopmans <zkoopmans@google.com> | 2020-10-23 16:03:04 -0700 |
---|---|---|
committer | Nicolas Lacasse <nlacasse@google.com> | 2020-10-23 16:13:46 -0700 |
commit | 634e14a09408e50ef70442c0114a8b1dd12c8d03 (patch) | |
tree | 49c5e37ea17f7e2efd80ff24db544c634f7fd754 /test/syscalls/linux/socket_test_util.cc | |
parent | a04c8ad4cee876a8dc5ebab43c0a4759602841d9 (diff) |
Fix socket_ipv4_udp_unbound_loopback_test_linux
Handle "Resource temporarily unavailable" EAGAIN errors with a select
call before calling recvmsg.
Also rename similar helper call from "RecvMsgTimeout" to "RecvTimeout",
because it calls "recv".
PiperOrigin-RevId: 338761695
Diffstat (limited to 'test/syscalls/linux/socket_test_util.cc')
-rw-r--r-- | test/syscalls/linux/socket_test_util.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/test/syscalls/linux/socket_test_util.cc b/test/syscalls/linux/socket_test_util.cc index e11792309..a760581b5 100644 --- a/test/syscalls/linux/socket_test_util.cc +++ b/test/syscalls/linux/socket_test_util.cc @@ -753,8 +753,7 @@ PosixErrorOr<int> SendMsg(int sock, msghdr* msg, char buf[], int buf_size) { return ret; } -PosixErrorOr<int> RecvMsgTimeout(int sock, char buf[], int buf_size, - int timeout) { +PosixErrorOr<int> RecvTimeout(int sock, char buf[], int buf_size, int timeout) { fd_set rfd; struct timeval to = {.tv_sec = timeout, .tv_usec = 0}; FD_ZERO(&rfd); @@ -767,6 +766,19 @@ PosixErrorOr<int> RecvMsgTimeout(int sock, char buf[], int buf_size, return ret; } +PosixErrorOr<int> RecvMsgTimeout(int sock, struct msghdr* msg, int timeout) { + fd_set rfd; + struct timeval to = {.tv_sec = timeout, .tv_usec = 0}; + 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 = RetryEINTR(recvmsg)(sock, msg, MSG_DONTWAIT)); + return ret; +} + void RecvNoData(int sock) { char data = 0; struct iovec iov; |