summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-16 17:04:36 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-16 17:04:36 +0100
commit92d75ca419994f3924dc14117b71f8706d9e1f57 (patch)
tree1d29d8786b40df5354c4ef6412e08c69ba3d5f25 /src/shared
parent4b8268f843b0da1cfe1995d93a0b1f95faccc454 (diff)
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.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 20aec2a5c9..c396fc7c6d 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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;
}