mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Allow infinite timeout in helpers
PiperOrigin-RevId: 595462226
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
@@ -766,11 +767,11 @@ PosixErrorOr<int> SendMsg(int sock, msghdr* msg, char buf[], int buf_size) {
|
||||
PosixErrorOr<int> 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<int> RecvTimeout(int sock, char buf[], int buf_size, int timeout) {
|
||||
PosixErrorOr<int> 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;
|
||||
|
||||
Reference in New Issue
Block a user