]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Implemented net_set_send_buffer_size() and net_set_recv_buffer_size().
authorStephan Bosch <stephan@dovecot.fi>
Thu, 19 May 2016 22:02:49 +0000 (00:02 +0200)
committerStephan Bosch <stephan@dovecot.fi>
Thu, 26 May 2016 01:05:44 +0000 (03:05 +0200)
These functions allow manipulating the kernel socket buffer sizes for a socket file descriptor.

src/lib/net.c
src/lib/net.h

index bf0ffafd542d9c67b8aca808d1cf2115778f735d..6206e654483de38b22c726f2efa56281406ac208 100644 (file)
@@ -351,6 +351,30 @@ int net_set_cork(int fd ATTR_UNUSED, bool cork ATTR_UNUSED)
 #endif
 }
 
+int net_set_send_buffer_size(int fd, size_t size)
+{
+       int opt;
+
+       if (size > INT_MAX) {
+               errno = EINVAL;
+               return -1;
+       }
+       opt = (int)size;
+       return setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(opt));
+}
+
+int net_set_recv_buffer_size(int fd, size_t size)
+{
+       int opt;
+
+       if (size > INT_MAX) {
+               errno = EINVAL;
+               return -1;
+       }
+       opt = (int)size;
+       return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt));
+}
+
 void net_get_ip_any4(struct ip_addr *ip)
 {
        ip->family = AF_INET;
index 51d3b82b61cbd56f5a06b5d1b827f5065028e9bf..a56a7a63052849668539454bc0649249714a5eff 100644 (file)
@@ -80,6 +80,10 @@ void net_set_nonblock(int fd, bool nonblock);
    Returns 0 if ok, -1 if failed. */
 int net_set_cork(int fd, bool cork) ATTR_NOWARN_UNUSED_RESULT;
 
+/* Set socket kernel buffer sizes */
+int net_set_send_buffer_size(int fd, size_t size);
+int net_set_recv_buffer_size(int fd, size_t size);
+
 /* Set IP to contain INADDR_ANY for IPv4 or IPv6. The IPv6 any address may
    include IPv4 depending on the system (Linux yes, BSD no). */
 void net_get_ip_any4(struct ip_addr *ip);