]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/io: negotiate socket buffer size
authorMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 27 Nov 2015 00:27:07 +0000 (01:27 +0100)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 27 Nov 2015 00:27:07 +0000 (01:27 +0100)
daemon/io.c

index 5000319a215cbfbb9a449d50916f44b6cf814057..0ecad301df5f9b1cf981b300a2e195ae08708f5e 100644 (file)
 #include "daemon/network.h"
 #include "daemon/worker.h"
 
+#define negotiate_bufsize(func, handle, bufsize_want) do { \
+    int bufsize = 0; func(handle, &bufsize); \
+       if (bufsize < bufsize_want) { \
+               bufsize = bufsize_want; \
+               func(handle, &bufsize); \
+       } \
+} while (0)
+
+static void check_bufsize(uv_handle_t* handle)
+{
+       /* We want to buffer at least N waves in advance.
+        * This is magic presuming we can pull in a whole recvmmsg width in one wave.
+        * Linux will double this the bufsize wanted.
+        */
+       const int bufsize_want = RECVMMSG_BATCH * 65535 * 2;
+       negotiate_bufsize(uv_recv_buffer_size, handle, bufsize_want);
+       negotiate_bufsize(uv_send_buffer_size, handle, bufsize_want);
+}
+
+#undef negotiate_bufsize
+
 static void *handle_alloc(uv_loop_t *loop, size_t size)
 {
        return malloc(size);
@@ -78,8 +99,8 @@ int udp_bind(uv_udp_t *handle, struct sockaddr *addr)
        if (ret != 0) {
                return ret;
        }
-
        handle->data = NULL;
+       check_bufsize((uv_handle_t *)handle);
        return io_start_read((uv_handle_t *)handle);
 }