changed the writability checker to use poll() to handle a high file descroptor in httpd-std.c.
added server.backlog-size option for httpd servers
This commit is contained in:
parent
cf0956cad6
commit
1fffa0324e
@ -80,12 +80,12 @@ host_triplet = @host@
|
||||
subdir = .
|
||||
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
|
||||
$(top_srcdir)/configure $(am__configure_deps) \
|
||||
$(srcdir)/README.in ac/ar-lib ac/compile ac/config.guess \
|
||||
ac/config.sub ac/depcomp ac/install-sh ac/missing ac/ltmain.sh \
|
||||
$(top_srcdir)/ac/ar-lib $(top_srcdir)/ac/compile \
|
||||
$(top_srcdir)/ac/config.guess $(top_srcdir)/ac/config.sub \
|
||||
$(top_srcdir)/ac/install-sh $(top_srcdir)/ac/ltmain.sh \
|
||||
$(top_srcdir)/ac/missing
|
||||
$(srcdir)/README.in README ac/ar-lib ac/compile \
|
||||
ac/config.guess ac/config.sub ac/depcomp ac/install-sh \
|
||||
ac/missing ac/ltmain.sh $(top_srcdir)/ac/ar-lib \
|
||||
$(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \
|
||||
$(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \
|
||||
$(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \
|
||||
$(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
|
@ -249,6 +249,7 @@ struct server_hostcfg_t
|
||||
typedef struct server_xtn_t server_xtn_t;
|
||||
struct server_xtn_t
|
||||
{
|
||||
int backlog_size;
|
||||
int nodir; /* no directory listing */
|
||||
|
||||
int num; /* the server number in the xli configuration */
|
||||
@ -2034,6 +2035,22 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_l
|
||||
|
||||
httpd_xtn = qse_httpd_getxtnstd (httpd);
|
||||
|
||||
qse_memset (&dope, 0, QSE_SIZEOF(dope));
|
||||
|
||||
pair = qse_xli_findpair (httpd_xtn->xli, list, QSE_T("backlog-size"));
|
||||
if (!pair) pair = qse_xli_findpair (httpd_xtn->xli, QSE_NULL, QSE_T("server-default.backlog-size"));
|
||||
if (pair == QSE_NULL || pair->val->type != QSE_XLI_STR)
|
||||
{
|
||||
dope.backlog_size = 256;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int v;
|
||||
v = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr, 10);
|
||||
if (v <= 0) v = 256;
|
||||
dope.backlog_size = v;
|
||||
}
|
||||
|
||||
pair = qse_xli_findpair (httpd_xtn->xli, list, QSE_T("bind"));
|
||||
if (pair == QSE_NULL || pair->val->type != QSE_XLI_STR)
|
||||
{
|
||||
@ -2042,7 +2059,6 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_l
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
qse_memset (&dope, 0, QSE_SIZEOF(dope));
|
||||
if (qse_strntonwad (((qse_xli_str_t*)pair->val)->ptr, ((qse_xli_str_t*)pair->val)->len, &dope.nwad) <= -1)
|
||||
{
|
||||
/* TOOD: logging */
|
||||
@ -2174,6 +2190,7 @@ static int open_config_file (qse_httpd_t* httpd)
|
||||
{ QSE_T("max-nofile"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
{ QSE_T("max-nproc"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
|
||||
|
||||
{ QSE_T("hooks"), { QSE_XLI_SCM_VALLIST | QSE_XLI_SCM_KEYNODUP, 0, 0 } },
|
||||
{ QSE_T("hooks.module"), { QSE_XLI_SCM_VALLIST | QSE_XLI_SCM_KEYALIAS, 0, 0 } },
|
||||
{ QSE_T("hooks.module.file"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
@ -2181,6 +2198,7 @@ static int open_config_file (qse_httpd_t* httpd)
|
||||
QSE_XLI_SCM_KEYNODUP | QSE_XLI_SCM_VALIFFY, 0, 0 } },
|
||||
|
||||
{ QSE_T("server-default"), { QSE_XLI_SCM_VALLIST | QSE_XLI_SCM_KEYNODUP, 0, 0 } },
|
||||
{ QSE_T("server-default.backlog-size"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
{ QSE_T("server-default.ssl-cert-file"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
{ QSE_T("server-default.ssl-key-file"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
{ QSE_T("server-default.root"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
@ -2236,6 +2254,7 @@ static int open_config_file (qse_httpd_t* httpd)
|
||||
{ QSE_T("server-default.proxy.urs-prerewrite-hook"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
|
||||
{ QSE_T("server"), { QSE_XLI_SCM_VALLIST, 0, 0 } },
|
||||
{ QSE_T("server.backlog-size"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
{ QSE_T("server.bind"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
{ QSE_T("server.ssl"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
{ QSE_T("server.ssl-cert-file"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
|
||||
|
@ -23,6 +23,8 @@ max-nproc = none;
|
||||
# default server configuration
|
||||
################################################
|
||||
server-default {
|
||||
backlog-size = 1024;
|
||||
|
||||
# default ssl certificate file
|
||||
#ssl-cert-file = "/etc/qse/cert.pem";
|
||||
# default ssl private key file
|
||||
@ -160,8 +162,8 @@ server-default {
|
||||
dns-server = "192.168.1.1:53";
|
||||
#dns-server = "[::1]:53";
|
||||
#dns-server = "@/tmp/dns.sock"; # unix socket prefixed with @
|
||||
#dns-timeout = 3
|
||||
#dns-retries = 2
|
||||
#dns-timeout = 3;
|
||||
#dns-retries = 2;
|
||||
dns-queries = a, aaaa;
|
||||
|
||||
#urs-enabled = yes; # no, yes,
|
||||
@ -174,8 +176,9 @@ server-default {
|
||||
}
|
||||
|
||||
server {
|
||||
backlog-size = 1024;
|
||||
bind = "0.0.0.0:1999";
|
||||
ssl = yes;
|
||||
ssl = no;
|
||||
|
||||
# you can create certificate/key files as shown below
|
||||
# openssl genrsa -out key.pem
|
||||
|
@ -772,6 +772,7 @@ struct qse_httpd_server_dope_t
|
||||
int flags; /* bitwise-ORed of qse_httpd_server_flag_t */
|
||||
qse_nwad_t nwad; /* binding address */
|
||||
unsigned int nwif; /* interface number to bind to */
|
||||
int backlog_size; /* backlog size for the listen call */
|
||||
qse_httpd_server_detach_t detach; /* executed when the server is detached */
|
||||
};
|
||||
|
||||
|
@ -109,6 +109,9 @@
|
||||
# if defined(HAVE_SYS_EPOLL_H)
|
||||
# include <sys/epoll.h>
|
||||
# endif
|
||||
# if defined(HAVE_SYS_POLL_H)
|
||||
# include <sys/poll.h>
|
||||
# endif
|
||||
# if defined(__linux__)
|
||||
# include <limits.h>
|
||||
# if defined(HAVE_LINUX_NETFILTER_IPV4_H)
|
||||
@ -1044,7 +1047,8 @@ bind_ok:
|
||||
}
|
||||
}
|
||||
|
||||
if (listen (fd, 10) <= -1)
|
||||
HTTPD_DBGOUT1 ("Setting backlog size to %d\n", server->dope.backlog_size);
|
||||
if (listen (fd, server->dope.backlog_size) <= -1)
|
||||
{
|
||||
qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
|
||||
goto oops;
|
||||
@ -1087,7 +1091,7 @@ static int server_accept (
|
||||
|
||||
#if 0
|
||||
/* TODO: implement maximum number of client per server??? */
|
||||
if (fd >= FD_SETSIZE)
|
||||
if (fd >= FD_SETSIZE - 1)
|
||||
{
|
||||
HTTPD_DEBUG ("ERROR: too many client - max %d, fd %d\n", (FD_SETSIZE, fd));
|
||||
/*TODO: qse_httpd_seterrnum (httpd, QSE_HTTPD_EXXXXX);*/
|
||||
@ -1857,10 +1861,27 @@ static int mux_writable (qse_httpd_t* httpd, qse_httpd_hnd_t handle, const qse_n
|
||||
tv = tmout? QSE_SECNSEC_TO_MSEC (tmout->sec, tmout->nsec): -1;
|
||||
return os2_select (&handle, 0, 1, 0, tv);
|
||||
|
||||
#elif defined(HAVE_SYS_POLL_H)
|
||||
struct pollfd p;
|
||||
int tv;
|
||||
|
||||
p.fd = handle;
|
||||
p.events = POLLOUT;
|
||||
p.revents = 0;
|
||||
|
||||
tv = tmout? QSE_SECNSEC_TO_MSEC(tmout->sec, tmout->nsec): -1;
|
||||
return poll (&p, 1, tv);
|
||||
#else
|
||||
|
||||
fd_set w;
|
||||
struct timeval tv, * tvp;
|
||||
|
||||
#if defined(FD_SETSIZE)
|
||||
/* NOTE: when the handle exceeds FD_SETSIZE,
|
||||
* select() may screw the entire program. */
|
||||
if (handle >= FD_SETSIZE - 1) return -1;
|
||||
#endif
|
||||
|
||||
FD_ZERO (&w);
|
||||
FD_SET (handle, &w);
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include <qse/cmn/mbwc.h>
|
||||
#include <qse/si/sio.h>
|
||||
|
||||
|
||||
#if !defined(QSE_HTTPD_DEFAULT_MODPREFIX)
|
||||
# if defined(_WIN32)
|
||||
# define QSE_HTTPD_DEFAULT_MODPREFIX "qsehttpd-"
|
||||
@ -1673,6 +1672,7 @@ static int invoke_client_task (
|
||||
qse_ntime_t tmout;
|
||||
tmout.sec = 0;
|
||||
tmout.nsec = 0;
|
||||
|
||||
if (httpd->opt.scb.mux.writable (httpd, client->handle, &tmout) <= 0)
|
||||
{
|
||||
/* it is not writable yet. so just skip
|
||||
@ -1732,7 +1732,6 @@ static int perform_client_task (
|
||||
else
|
||||
{
|
||||
/* locate an active client to the tail of the client list */
|
||||
|
||||
qse_gettime (&client->last_active); /* TODO: error check??? */
|
||||
move_client_to_tail (httpd, client);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user