add reconfigurable connection baglog

This commit is contained in:
Xuan Sang LE 2018-02-05 23:04:02 +01:00
parent fb43aac923
commit 101cbead6c
3 changed files with 7 additions and 1 deletions

View File

@ -9,6 +9,7 @@ typedef struct {
char* htdocs;
char* tmpdir;
dictionary rules;
int backlog;
}config_t;
extern config_t server_config;

View File

@ -339,7 +339,8 @@ int startup(unsigned *port)
error_die("getsockname");
*port = ntohs(name.sin_port);
}
if (listen(httpd, 5) < 0)
printf("back log is %d\n", server_config.backlog);
if (listen(httpd, server_config.backlog) < 0)
error_die("listen");
return(httpd);
}

View File

@ -22,6 +22,9 @@ static int config_handler(void* conf, const char* section, const char* name,
pconfig->htdocs = strdup(value);
} else if(MATCH("SERVER", "tmpdir")) {
pconfig->tmpdir = strdup(value);
}
else if(MATCH("SERVER", "backlog")) {
pconfig->backlog = atoi(value);
}
else if (strcmp(section, "RULES") == 0)
{
@ -61,6 +64,7 @@ void load_config(const char* file)
server_config.db_path = "databases/";
server_config.htdocs = "htdocs";
server_config.tmpdir = "tmp";
server_config.backlog = 100;
server_config.rules = dict();
if (ini_parse(file, config_handler, &server_config) < 0) {
LOG("Can't load '%s'\n. Used defaut configuration", file);