From e4336fe612d4e95cd6fb76b9ced6a9599ebe1990 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 20 Oct 2015 15:24:51 +0100 Subject: [PATCH] Implement batch accept in server. --- utils/rspamd_http_bench.c | 5 ++++- utils/rspamd_http_server.c | 43 +++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/utils/rspamd_http_bench.c b/utils/rspamd_http_bench.c index 286a3ddb1..f30c2bfe6 100644 --- a/utils/rspamd_http_bench.c +++ b/utils/rspamd_http_bench.c @@ -30,6 +30,7 @@ #include "cryptobox.h" #include "unix-std.h" #include +#include #ifdef HAVE_SYS_WAIT_H #include @@ -124,10 +125,12 @@ rspamd_http_client_func (struct event_base *ev_base, double *latency) struct rspamd_http_connection *conn; gchar urlbuf[PATH_MAX]; struct client_cbdata *cb; - gint fd; + gint fd, flags; g_assert ( (fd = rspamd_inet_address_connect (addr, SOCK_STREAM, TRUE)) != -1); + flags = 1; + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof (flags)); conn = rspamd_http_connection_new (rspamd_client_body, rspamd_client_err, rspamd_client_finish, RSPAMD_HTTP_CLIENT_SIMPLE, RSPAMD_HTTP_CLIENT, c); diff --git a/utils/rspamd_http_server.c b/utils/rspamd_http_server.c index 71d74ee7d..3aefe6b9f 100644 --- a/utils/rspamd_http_server.c +++ b/utils/rspamd_http_server.c @@ -139,26 +139,31 @@ rspamd_server_accept (gint fd, short what, void *arg) rspamd_inet_addr_t *addr; gint nfd; - if ((nfd = - rspamd_accept_from_socket (fd, &addr)) == -1) { - rspamd_fprintf (stderr, "accept failed: %s", strerror (errno)); - return; - } - /* Check for EAGAIN */ - if (nfd == 0) { - return; - } + do { + if ((nfd = + rspamd_accept_from_socket (fd, &addr)) == -1) { + rspamd_fprintf (stderr, "accept failed: %s", strerror (errno)); + return; + } + /* Check for EAGAIN */ + if (nfd == 0) { + return; + } - rspamd_inet_address_destroy (addr); - session = g_slice_alloc (sizeof (*session)); - session->conn = rspamd_http_connection_new (NULL, rspamd_server_error, - rspamd_server_finish, 0, RSPAMD_HTTP_SERVER, c); - rspamd_http_connection_set_key (session->conn, server_key); - rspamd_http_connection_read_message (session->conn, session, nfd, &io_tv, - ev_base); - session->reply = FALSE; - session->fd = nfd; - session->ev_base = ev_base; + rspamd_inet_address_destroy (addr); + session = g_slice_alloc (sizeof (*session)); + session->conn = rspamd_http_connection_new (NULL, rspamd_server_error, + rspamd_server_finish, 0, RSPAMD_HTTP_SERVER, c); + rspamd_http_connection_set_key (session->conn, server_key); + rspamd_http_connection_read_message (session->conn, + session, + nfd, + &io_tv, + ev_base); + session->reply = FALSE; + session->fd = nfd; + session->ev_base = ev_base; + } while (nfd > 0); } static void -- 2.39.5