Skip to content

Commit

Permalink
Add option to specify listen() queue length.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkk committed Jan 27, 2012
1 parent 8839230 commit 8156e44
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions redsocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 },
{ }
};

Expand All @@ -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 = &section->entries[0]; entry->key; entry++)
entry->addr =
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions redsocks.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions redsocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8156e44

Please sign in to comment.