]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Allow to restore SSL handlers after keepalive pooling
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Dec 2021 11:37:33 +0000 (11:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Dec 2021 11:37:33 +0000 (11:37 +0000)
src/libserver/http/http_connection.c
src/libserver/ssl_util.c
src/libserver/ssl_util.h

index 3dfe8e86cb2d5c9545cc0877de4cea6ffa15a558..e82c543c2da3dedae5d1761b373fcbc4dc77a39a 100644 (file)
@@ -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;
        }
 
index b4e905619dab161925f08ee48d0d200c5a2af47f..c229b679446a7776052918e8a5dd09d7de4880e8 100644 (file)
@@ -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)
index f3593387f55b716c923496dcd12f2210506c1c1c..f2d591b563c7b2f06ebceac0e1e876f8380c6b4f 100644 (file)
@@ -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