commit b81a068: [Rework] Allow to restore SSL handlers after keepalive pooling

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Dec 8 11:49:06 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-12-08 11:37:33 +0000
URL: https://github.com/rspamd/rspamd/commit/b81a068aea8dca451b1f106ef191c0820db52c52

[Rework] Allow to restore SSL handlers after keepalive pooling

---
 src/libserver/http/http_connection.c | 11 +++++++++++
 src/libserver/ssl_util.c             | 15 +++++++++++++++
 src/libserver/ssl_util.h             | 12 ++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/src/libserver/http/http_connection.c b/src/libserver/http/http_connection.c
index 3dfe8e86c..e82c543c2 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 b4e905619..c229b6794 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 f3593387f..f2d591b56 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


More information about the Commits mailing list