Commit 296d0bc9 296d0bc958142cafe0e839cd43236c14c8310ee2 by Sergey Poznyakoff

Allow to configure the length of the backlog queue for TCP servers

New statement backlog is provided in the server block.

* include/mailutils/server.h (mu_m_server_cfg_init): Pass
mu_m_server_t as first argument.
* libmailutils/server/msrv.c (mu_m_server_cfg_init): Pass
mu_m_server_t as first argument. Customize available statements
depending on the type of server (tcp vs udp).
New statement "backlog" available for tcp servers.

* comsat/comsat.c: Update call to mu_m_server_cfg_init
* imap4d/imap4d.c: Likewise.
* pop3d/pop3d.c: Likewise.
* maidag/maidag.c: Likewise.
1 parent 37388665
......@@ -566,7 +566,6 @@ main (int argc, char **argv)
mu_argp_init (NULL, NULL);
comsat_init ();
mu_acl_cfg_init ();
mu_m_server_cfg_init (NULL);
mu_m_server_create (&server, program_version);
mu_m_server_set_type (server, MU_IP_UDP);
mu_m_server_set_conn (server, comsat_connection);
......@@ -575,6 +574,8 @@ main (int argc, char **argv)
mu_m_server_set_max_children (server, 20);
/* FIXME mu_m_server_set_pidfile (); */
mu_m_server_set_default_port (server, 512);
mu_m_server_cfg_init (server, NULL);
/* FIXME: timeout is not needed. How to disable it? */
mu_log_syslog = 1;
......
......@@ -942,7 +942,6 @@ main (int argc, char **argv)
mu_tcpwrapper_cfg_init ();
manlock_cfg_init ();
mu_acl_cfg_init ();
mu_m_server_cfg_init (imap4d_srv_param);
mu_argp_init (NULL, NULL);
......@@ -956,6 +955,7 @@ main (int argc, char **argv)
mu_m_server_set_default_port (server, 143);
mu_m_server_set_timeout (server, 1800); /* RFC2060: 30 minutes. */
mu_m_server_set_strexit (server, mu_strexit);
mu_m_server_cfg_init (server, imap4d_srv_param);
mu_alloc_die_hook = imap4d_alloc_die;
......
......@@ -142,7 +142,7 @@ void mu_m_server_stop (int code);
int mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen);
struct mu_cfg_param;
void mu_m_server_cfg_init (struct mu_cfg_param *app_param);
void mu_m_server_cfg_init (mu_m_server_t msrv, struct mu_cfg_param *app_param);
#endif
......
......@@ -24,6 +24,7 @@
#endif
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
......@@ -932,8 +933,32 @@ static struct mu_cfg_param server_cfg_param[] = {
{ NULL }
};
static int
_cb_backlog (void *data, mu_config_value_t *val)
{
mu_ip_server_t *psrv = data;
int backlog;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (sscanf (val->v.string, "%d", &backlog) != 1 || backlog <= 0
|| mu_tcp_server_set_backlog (*psrv, backlog))
{
mu_error (_("invalid argument"));
return 1;
}
return 0;
}
static struct mu_cfg_param server_tcp_param[] = {
{ "backlog", mu_cfg_callback,
NULL, mu_offsetof (struct mu_srv_config, tcpsrv), _cb_backlog,
N_("Size of the queue of pending connections") },
{ NULL }
};
void
mu_m_server_cfg_init (struct mu_cfg_param *app_param)
mu_m_server_cfg_init (mu_m_server_t srv, struct mu_cfg_param *app_param)
{
struct mu_cfg_section *section;
if (mu_create_canned_section ("server", &section) == 0)
......@@ -941,6 +966,8 @@ mu_m_server_cfg_init (struct mu_cfg_param *app_param)
section->parser = server_section_parser;
section->label = N_("ipaddr[:port]");
mu_cfg_section_add_params (section, server_cfg_param);
if (srv->deftype == MU_IP_TCP)
mu_cfg_section_add_params (section, server_tcp_param);
if (app_param)
mu_cfg_section_add_params (section, app_param);
}
......
......@@ -522,7 +522,6 @@ main (int argc, char *argv[])
mu_tcpwrapper_cfg_init ();
mu_acl_cfg_init ();
mu_m_server_cfg_init (NULL);
maidag_cfg_init ();
/* Parse command line */
......@@ -537,6 +536,7 @@ main (int argc, char *argv[])
mu_m_server_set_mode (server, MODE_INTERACTIVE);
mu_m_server_set_max_children (server, 20);
mu_m_server_set_timeout (server, 600);
mu_m_server_cfg_init (server, NULL);
mu_log_syslog = -1;
mu_log_print_severity = 1;
......
......@@ -575,7 +575,6 @@ main (int argc, char **argv)
mu_tcpwrapper_cfg_init ();
manlock_cfg_init ();
mu_acl_cfg_init ();
mu_m_server_cfg_init (pop3d_srv_param);
mu_argp_init (NULL, NULL);
......@@ -589,6 +588,7 @@ main (int argc, char **argv)
mu_m_server_set_default_port (server, 110);
mu_m_server_set_timeout (server, 600);
mu_m_server_set_strexit (server, mu_strexit);
mu_m_server_cfg_init (server, pop3d_srv_param);
mu_alloc_die_hook = pop3d_alloc_die;
......