From: Marek VavruĊĦa Date: Fri, 27 Nov 2015 00:27:07 +0000 (+0100) Subject: daemon/io: negotiate socket buffer size X-Git-Tag: v1.0.0-beta3~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d75ba2b19b91c9eb7f107fc23a6feff06d0b20d6;p=thirdparty%2Fknot-resolver.git daemon/io: negotiate socket buffer size --- diff --git a/daemon/io.c b/daemon/io.c index 5000319a2..0ecad301d 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -23,6 +23,27 @@ #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); }