aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-20 15:24:51 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-20 15:24:51 +0100
commite4336fe612d4e95cd6fb76b9ced6a9599ebe1990 (patch)
tree0245846748ce51a179178bf77a3452842c39f62b
parentafc786bb1ca868077219b133d7611b71957b0b44 (diff)
downloadrspamd-e4336fe612d4e95cd6fb76b9ced6a9599ebe1990.tar.gz
rspamd-e4336fe612d4e95cd6fb76b9ced6a9599ebe1990.zip
Implement batch accept in server.
-rw-r--r--utils/rspamd_http_bench.c5
-rw-r--r--utils/rspamd_http_server.c43
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 <math.h>
+#include <netinet/tcp.h>
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
@@ -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