Fix select call in socket utils

From the `select` manpage:
```
      nfds   This argument should be set to the highest-numbered file
              descriptor in any of the three sets, plus 1...
```

PiperOrigin-RevId: 595697728
This commit is contained in:
Bruno Dal Bo
2024-01-04 07:24:31 -08:00
committed by gVisor bot
parent 5c8be5da4d
commit 5c41ffabdb
+4 -2
View File
@@ -771,7 +771,8 @@ PosixErrorOr<int> RecvTimeout(int sock, char buf[], int buf_size, int timeout) {
FD_ZERO(&rfd);
FD_SET(sock, &rfd);
int ret;
RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, to_ptr));
RETURN_ERROR_IF_SYSCALL_FAIL(ret =
select(sock + 1, &rfd, NULL, NULL, to_ptr));
RETURN_ERROR_IF_SYSCALL_FAIL(
ret = RetryEINTR(recv)(sock, buf, buf_size, MSG_DONTWAIT));
return ret;
@@ -785,7 +786,8 @@ PosixErrorOr<int> RecvMsgTimeout(int sock, struct msghdr* msg, int timeout) {
FD_SET(sock, &rfd);
int ret;
RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, to_ptr));
RETURN_ERROR_IF_SYSCALL_FAIL(ret =
select(sock + 1, &rfd, NULL, NULL, to_ptr));
RETURN_ERROR_IF_SYSCALL_FAIL(
ret = RetryEINTR(recvmsg)(sock, msg, MSG_DONTWAIT));
return ret;