From d75ba2b19b91c9eb7f107fc23a6feff06d0b20d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Vavru=C5=A1a?= Date: Fri, 27 Nov 2015 01:27:07 +0100 Subject: [PATCH] daemon/io: negotiate socket buffer size --- daemon/io.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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); } -- 2.47.2