mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
util: try harder to increase the send/recv buffers of sockets
If we have the priviliges we will try SO_SNDBUFFORCE/SO_RCVBUFFORCE and only fall back to SO_SNDBUF/SO_RCVBUF if that fails.
This commit is contained in:
parent
4b8268f843
commit
92d75ca419
@ -4936,15 +4936,15 @@ int fd_inc_sndbuf(int fd, size_t n) {
|
||||
socklen_t l = sizeof(value);
|
||||
|
||||
r = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &l);
|
||||
if (r >= 0 &&
|
||||
l == sizeof(value) &&
|
||||
(size_t) value >= n*2)
|
||||
if (r >= 0 && l == sizeof(value) && (size_t) value >= n*2)
|
||||
return 0;
|
||||
|
||||
/* If we have the privileges we will ignore the kernel limit. */
|
||||
|
||||
value = (int) n;
|
||||
r = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value));
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &value, sizeof(value)) < 0)
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value)) < 0)
|
||||
return -errno;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -4954,16 +4954,15 @@ int fd_inc_rcvbuf(int fd, size_t n) {
|
||||
socklen_t l = sizeof(value);
|
||||
|
||||
r = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, &l);
|
||||
if (r >= 0 &&
|
||||
l == sizeof(value) &&
|
||||
(size_t) value >= n*2)
|
||||
if (r >= 0 && l == sizeof(value) && (size_t) value >= n*2)
|
||||
return 0;
|
||||
|
||||
value = (int) n;
|
||||
r = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value));
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
/* If we have the privileges we will ignore the kernel limit. */
|
||||
|
||||
value = (int) n;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &value, sizeof(value)) < 0)
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value)) < 0)
|
||||
return -errno;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user