]> source.dussan.org Git - rspamd.git/commitdiff
[Project] More fixes to keepalive http pool
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Mar 2019 16:19:14 +0000 (16:19 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Mar 2019 16:19:14 +0000 (16:19 +0000)
src/libutil/http_connection.c
src/libutil/http_context.c

index 9e43e21e222680c750340df3e4ba42f55873fbdf..dc3bfa9c093a3ae2258826a7ae4d5234319a0fed 100644 (file)
@@ -356,6 +356,7 @@ rspamd_http_on_headers_complete (http_parser * parser)
                if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
                        rspamd_http_context_push_keepalive (conn->priv->ctx, conn,
                                        msg, conn->priv->ctx->ev_base);
+                       rspamd_http_connection_reset (conn);
                }
                else {
                        conn->finished = TRUE;
@@ -539,6 +540,7 @@ rspamd_http_on_headers_complete_decrypted (http_parser *parser)
                if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
                        rspamd_http_context_push_keepalive (conn->priv->ctx, conn,
                                        msg, conn->priv->ctx->ev_base);
+                       rspamd_http_connection_reset (conn);
                }
                else {
                        conn->finished = TRUE;
@@ -697,6 +699,7 @@ rspamd_http_on_message_complete (http_parser * parser)
                if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
                        rspamd_http_context_push_keepalive (conn->priv->ctx, conn,
                                        priv->msg, conn->priv->ctx->ev_base);
+                       rspamd_http_connection_reset (conn);
                }
                else {
                        conn->finished = TRUE;
@@ -1135,6 +1138,10 @@ rspamd_http_connection_new_keepalive (struct rspamd_http_context *ctx,
                return NULL;
        }
 
+       if (ctx == NULL) {
+               ctx = rspamd_http_context_default ();
+       }
+
        conn = rspamd_http_context_check_keepalive (ctx, addr, host);
 
        if (conn) {
index d8b576d1fcf921e33e1891f02643d0734d3ffd43..7f1de0c366523a834664379637397451bf737cf2 100644 (file)
@@ -78,6 +78,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
 
        static const int default_kp_size = 1024;
        static const gdouble default_rotate_time = 120;
+       static const gdouble default_keepalive_interval = 65;
        static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
 
        ctx = g_malloc0 (sizeof (*ctx));
@@ -85,6 +86,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
        ctx->config.kp_cache_size_server = default_kp_size;
        ctx->config.client_key_rotate_time = default_rotate_time;
        ctx->config.user_agent = default_user_agent;
+       ctx->config.keepalive_interval = default_keepalive_interval;
 
        if (cfg) {
                ctx->ssl_ctx = cfg->libs_ctx->ssl_ctx;
@@ -171,6 +173,14 @@ rspamd_http_context_create (struct rspamd_config *cfg,
                                        ctx->config.user_agent = NULL;
                                }
                        }
+
+                       const ucl_object_t *keepalive_interval;
+
+                       keepalive_interval = ucl_object_lookup (client_obj, "keepalive_interval");
+
+                       if (keepalive_interval) {
+                               ctx->config.keepalive_interval = ucl_object_todouble (keepalive_interval);
+                       }
                }
 
                server_obj = ucl_object_lookup (http_obj, "server");
@@ -443,7 +453,7 @@ rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx,
 
        event_set (&cbdata->ev, conn->fd, EV_READ|EV_TIMEOUT,
                        rspamd_http_keepalive_handler,
-                       &cbdata);
+                       cbdata);
 
        double_to_tv (timeout, &tv);
        event_base_set (ev_base, &cbdata->ev);