Reenable accepting connections after hitting the limit (fixes #2195)

This commit is contained in:
Stefan Bühler 2010-05-07 22:31:29 +02:00
parent 51ecc24ddb
commit b094a9ad16
2 changed files with 28 additions and 8 deletions

View File

@ -690,11 +690,8 @@ static void fastcgi_server_fd_cb(struct ev_loop *loop, ev_io *w, int revents) {
/* we were stopped _after_ we had a connection */
return;
case EMFILE:
if (0 == fsrv->max_connections) {
fsrv->max_connections = fsrv->connections->len / 2;
} else {
fsrv->max_connections = fsrv->max_connections / 2;
}
fsrv->max_connections = fsrv->connections->len / 2;
if (fsrv->max_connections < 1) fsrv->max_connections = 1;
ERROR("dropped connection limit to %u as we got EMFILE\n", fsrv->max_connections);
ev_io_rem_events(loop, w, EV_READ);
return;
@ -722,6 +719,7 @@ static void fastcgi_server_fd_cb(struct ev_loop *loop, ev_io *w, int revents) {
static void fastcgi_cleanup_connections(fastcgi_server *fsrv) {
guint i;
gboolean closed_con;
for (i = 0; i < fsrv->connections->len; ) {
fastcgi_connection *fcon = g_ptr_array_index(fsrv->connections, i);
@ -732,10 +730,15 @@ static void fastcgi_cleanup_connections(fastcgi_server *fsrv) {
g_ptr_array_set_size(fsrv->connections, l);
t_fcon->fcon_id = i;
fastcgi_connection_free(fcon);
closed_con = TRUE;
} else {
i++;
}
}
if (closed_con && fsrv->connections->len < fsrv->max_connections) {
ev_io_add_events(fsrv->loop, &fsrv->fd_watcher, EV_READ);
}
}
static void fastcgi_closing_cb(struct ev_loop *loop, ev_prepare *w, int revents) {

View File

@ -494,11 +494,11 @@ static const fastcgi_callbacks cgi_callbacks = {
/* cb_reset_connection: */ fcgi_cgi_reset_connection
};
static fcgi_cgi_server* fcgi_cgi_server_create(struct ev_loop *loop, int fd) {
static fcgi_cgi_server* fcgi_cgi_server_create(struct ev_loop *loop, int fd, guint maxconns) {
fcgi_cgi_server* srv = g_slice_new0(fcgi_cgi_server);
srv->loop = loop;
srv->aborted_pending_childs = g_ptr_array_new();
srv->fsrv = fastcgi_server_create(loop, fd, &cgi_callbacks, 10);
srv->fsrv = fastcgi_server_create(loop, fd, &cgi_callbacks, maxconns);
srv->fsrv->data = srv;
return srv;
}
@ -539,6 +539,23 @@ static void sigint_cb(struct ev_loop *loop, struct ev_signal *w, int revents) {
}
}
typedef struct {
gint maxconns;
gboolean show_version;
} options;
static options opts = {
/* maxconns:*/ 16,
/* version: */ FALSE,
};
static const GOptionEntry entries[] = {
{ "max-connections", 'c', 0, G_OPTION_ARG_INT, &opts.maxconns, "Maximum number of connections (default 16)", "number" },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &opts.show_version, "Show version", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
int main(int argc, char **argv) {
struct ev_loop *loop;
fcgi_cgi_server* srv;
@ -546,7 +563,7 @@ int main(int argc, char **argv) {
UNUSED(argv);
loop = ev_default_loop(0);
srv = fcgi_cgi_server_create(loop, 0);
srv = fcgi_cgi_server_create(loop, 0, opts.maxconns);
signal(SIGPIPE, SIG_IGN);
CATCH_SIGNAL(loop, sigint_cb, INT);