socket-util: reset length argument for second getsockopt call in fd_[gs]et_rcvbuf

In case the first getsockopt() call changes the value.
This commit is contained in:
Christian Göttsche 2020-09-14 19:40:42 +02:00 committed by Yu Watanabe
parent 3c460bfde6
commit 67f5ae2d69
1 changed files with 2 additions and 0 deletions

View File

@ -640,6 +640,7 @@ int fd_set_sndbuf(int fd, size_t n, bool increase) {
/* SO_SNDBUF above may set to the kernel limit, instead of the requested size.
* So, we need to check the actual buffer size here. */
l = sizeof(value);
r = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &l);
if (r >= 0 && l == sizeof(value) && increase ? (size_t) value >= n*2 : (size_t) value == n*2)
return 1;
@ -670,6 +671,7 @@ int fd_set_rcvbuf(int fd, size_t n, bool increase) {
/* SO_RCVBUF above may set to the kernel limit, instead of the requested size.
* So, we need to check the actual buffer size here. */
l = sizeof(value);
r = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, &l);
if (r >= 0 && l == sizeof(value) && increase ? (size_t) value >= n*2 : (size_t) value == n*2)
return 1;