From: Vsevolod Stakhov Date: Wed, 8 Dec 2021 11:37:33 +0000 (+0000) Subject: [Rework] Allow to restore SSL handlers after keepalive pooling X-Git-Tag: 3.2~182 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b81a068aea8dca451b1f106ef191c0820db52c52;p=thirdparty%2Frspamd.git [Rework] Allow to restore SSL handlers after keepalive pooling --- diff --git a/src/libserver/http/http_connection.c b/src/libserver/http/http_connection.c index 3dfe8e86cb..e82c543c2d 100644 --- a/src/libserver/http/http_connection.c +++ b/src/libserver/http/http_connection.c @@ -1260,6 +1260,17 @@ rspamd_http_connection_new_client_keepalive (struct rspamd_http_context *ctx, opts & RSPAMD_HTTP_CLIENT_SSL); if (conn) { + struct rspamd_http_connection_private *priv; + + priv = conn->priv; + + if (priv->ssl) { + rspamd_ssl_connection_restore_handlers (priv->ssl, + rspamd_http_event_handler, + rspamd_http_ssl_err_handler, + conn); + } + return conn; } diff --git a/src/libserver/ssl_util.c b/src/libserver/ssl_util.c index b4e905619d..c229b67944 100644 --- a/src/libserver/ssl_util.c +++ b/src/libserver/ssl_util.c @@ -754,6 +754,21 @@ rspamd_ssl_connect_fd (struct rspamd_ssl_connection *conn, gint fd, return TRUE; } +void +rspamd_ssl_connection_restore_handlers (struct rspamd_ssl_connection *conn, + rspamd_ssl_handler_t handler, + rspamd_ssl_error_handler_t err_handler, + gpointer handler_data) +{ + conn->handler = handler; + conn->err_handler = err_handler; + conn->handler_data = handler_data; + + rspamd_ev_watcher_stop (conn->event_loop, conn->ev); + rspamd_ev_watcher_init (conn->ev, conn->fd, EV_WRITE, rspamd_ssl_event_handler, conn); + rspamd_ev_watcher_start (conn->event_loop, conn->ev, conn->ev->timeout); +} + gssize rspamd_ssl_read (struct rspamd_ssl_connection *conn, gpointer buf, gsize buflen) diff --git a/src/libserver/ssl_util.h b/src/libserver/ssl_util.h index f3593387f5..f2d591b563 100644 --- a/src/libserver/ssl_util.h +++ b/src/libserver/ssl_util.h @@ -56,6 +56,18 @@ gboolean rspamd_ssl_connect_fd (struct rspamd_ssl_connection *conn, gint fd, rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler, gpointer handler_data); +/** + * Restores SSL handlers for the existing ssl connection (e.g. after keepalive) + * @param conn + * @param handler + * @param err_handler + * @param handler_data + */ +void rspamd_ssl_connection_restore_handlers (struct rspamd_ssl_connection *conn, + rspamd_ssl_handler_t handler, + rspamd_ssl_error_handler_t err_handler, + gpointer handler_data); + /** * Perform async read from SSL socket * @param conn