Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit d2d5056f authored by rswindell's avatar rswindell

If a service is full (maximum clients reached), rather than accept/close the

connection, the connection is ignored by default unless the FULL_ACCEPT
service option is used.
Each service has a configurable listen backlog now (defaults to SOMAXCONN),
this value can only be configured by using ListenBacklog in the services.ini.
parent c382e5ea
......@@ -90,6 +90,7 @@ typedef struct {
char cmd[128];
DWORD max_clients;
DWORD options;
int listen_backlog;
/* These are run-time state and stat vars */
DWORD clients;
DWORD served;
......@@ -108,6 +109,7 @@ static ini_bitdesc_t service_options[] = {
{ SERVICE_OPT_STATIC ,"STATIC" },
{ SERVICE_OPT_STATIC_LOOP ,"LOOP" },
{ SERVICE_OPT_NATIVE ,"NATIVE" },
{ SERVICE_OPT_FULL_ACCEPT ,"FULL_ACCEPT" },
/* terminator */
{ -1 ,NULL }
};
......@@ -1282,6 +1284,7 @@ static service_t* read_services_cfg(service_t* service, char* services_cfg, DWOR
service=np;
memset(&service[*services],0,sizeof(service_t));
service[*services].socket=INVALID_SOCKET;
service[*services].listen_backlog=SOMAXCONN;
tp=p;
while(*tp && *tp>' ') tp++;
......@@ -1326,6 +1329,7 @@ static service_t* read_services_ini(service_t* service, char* services_ini, DWOR
serv.socket=INVALID_SOCKET;
serv.port=iniGetShortInt(fp,sec_list[i],"Port",0);
serv.max_clients=iniGetInteger(fp,sec_list[i],"MaxClients",0);
serv.listen_backlog=iniGetInteger(fp,sec_list[i],"ListenBacklog",SOMAXCONN);
serv.options=iniGetBitField(fp,sec_list[i],"Options",service_options,0);
SAFECOPY(serv.cmd,iniGetString(fp,sec_list[i],"Command","",cmd));
......@@ -1589,7 +1593,7 @@ void DLLCALL services_thread(void* arg)
,service[i].port);
if(!(service[i].options&SERVICE_OPT_UDP)) {
if(listen(socket,10)!=0) {
if(listen(socket,service[i].listen_backlog)!=0) {
lprintf("%04d !ERROR %d listening on %s socket"
,socket, ERROR_VALUE, service[i].protocol);
close_socket(socket);
......@@ -1666,6 +1670,9 @@ void DLLCALL services_thread(void* arg)
continue;
if(service[i].socket==INVALID_SOCKET)
continue;
if(!(service[i].options&SERVICE_OPT_FULL_ACCEPT)
&& service[i].max_clients && service[i].clients >= service[i].max_clients)
continue;
FD_SET(service[i].socket,&socket_set);
if(service[i].socket>high_socket)
high_socket=service[i].socket;
......
......@@ -75,6 +75,7 @@ typedef struct {
#define SERVICE_OPT_STATIC (1<<1) /* Static service (accepts client connectsions) */
#define SERVICE_OPT_STATIC_LOOP (1<<2) /* Loop static service until terminated */
#define SERVICE_OPT_NATIVE (1<<3) /* non-JavaScript service */
#define SERVICE_OPT_FULL_ACCEPT (1<<4) /* Accept/close connections when server is full */
#ifdef __cplusplus
extern "C" {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment