From 8156e442c2125c01a3be5ac793c95372dced1563 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Fri, 27 Jan 2012 21:04:22 +0400 Subject: [PATCH] Add option to specify listen() queue length. --- redsocks.c | 10 +++++++--- redsocks.conf.example | 4 ++++ redsocks.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/redsocks.c b/redsocks.c index 73f27e33..5f627e5d 100644 --- a/redsocks.c +++ b/redsocks.c @@ -35,8 +35,6 @@ #include "utils.h" -#define THE_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING 42 - #define REDSOCKS_RELAY_HALFBUFF 4096 @@ -66,6 +64,7 @@ static parser_entry redsocks_entries[] = { .key = "type", .type = pt_pchar }, { .key = "login", .type = pt_pchar }, { .key = "password", .type = pt_pchar }, + { .key = "listenq", .type = pt_uint16 }, { } }; @@ -90,6 +89,10 @@ static int redsocks_onenter(parser_section *section) instance->config.bindaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); instance->config.relayaddr.sin_family = AF_INET; instance->config.relayaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + /* Default value can be checked in run-time, but I doubt anyone needs that. + * Linux: sysctl net.core.somaxconn + * FreeBSD: sysctl kern.ipc.somaxconn */ + instance->config.listenq = SOMAXCONN; for (parser_entry *entry = §ion->entries[0]; entry->key; entry++) entry->addr = @@ -100,6 +103,7 @@ static int redsocks_onenter(parser_section *section) (strcmp(entry->key, "type") == 0) ? (void*)&instance->config.type : (strcmp(entry->key, "login") == 0) ? (void*)&instance->config.login : (strcmp(entry->key, "password") == 0) ? (void*)&instance->config.password : + (strcmp(entry->key, "listenq") == 0) ? (void*)&instance->config.listenq : NULL; section->data = instance; return 0; @@ -705,7 +709,7 @@ static int redsocks_init_instance(redsocks_instance *instance) goto fail; } - error = listen(fd, THE_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING); // does anyone know better value? + error = listen(fd, instance->config.listenq); if (error) { log_errno(LOG_ERR, "listen"); goto fail; diff --git a/redsocks.conf.example b/redsocks.conf.example index fd7ee38a..b27ef8ad 100644 --- a/redsocks.conf.example +++ b/redsocks.conf.example @@ -43,6 +43,10 @@ redsocks { local_ip = 127.0.0.1; local_port = 12345; + // listen() queue length. Default value is SOMAXCONN and it should be + // good enough for most of us. + // listenq = 128; + // `ip' and `port' are IP and tcp-port of proxy-server // You can also use hostname instead of IP, only one (random) // address of multihomed host will be used. diff --git a/redsocks.h b/redsocks.h index 13e08dbb..6b34afe9 100644 --- a/redsocks.h +++ b/redsocks.h @@ -29,6 +29,7 @@ typedef struct redsocks_config_t { char *type; char *login; char *password; + uint16_t listenq; } redsocks_config; typedef struct redsocks_instance_t {