From d9de7ca3d021516710f0abdb84b2ad70393e51e7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 2 Sep 2012 18:48:46 +0200 Subject: [PATCH] MEDIUM: connection: avoid calling handshakes when polling is required If a data handler suddenly switches to a handshake mode and detects the need for polling in either direction, we don't want to loop again through the handshake handlers because we know we won't be able to do anything. Similarly, we don't want to call again the data handlers after a loop through the handshake handlers if polling is required. No performance change was observed, it might only be observed during high rate SSL renegociation. --- src/connection.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/connection.c b/src/connection.c index 15b94856f..cb314add4 100644 --- a/src/connection.c +++ b/src/connection.c @@ -41,7 +41,7 @@ int conn_fd_handler(int fd) * work must explicitly disable events it's not interested in. */ while (unlikely(conn->flags & CO_FL_HANDSHAKE)) { - if (unlikely(conn->flags & CO_FL_ERROR)) + if (unlikely(conn->flags & (CO_FL_ERROR|CO_FL_WAIT_RD|CO_FL_WAIT_WR))) goto leave; if (conn->flags & CO_FL_ACCEPT_PROXY) @@ -65,7 +65,8 @@ int conn_fd_handler(int fd) conn_session_complete(conn, CO_FL_INIT_SESS) < 0) return 0; - if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR)) + if ((fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR)) && + !(conn->flags & (CO_FL_WAIT_RD|CO_FL_WAIT_ROOM))) conn->app_cb->recv(conn); if (unlikely(conn->flags & CO_FL_ERROR)) @@ -77,7 +78,8 @@ int conn_fd_handler(int fd) if (unlikely(conn->flags & CO_FL_HANDSHAKE)) goto process_handshake; - if (fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR)) + if ((fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR)) && + !(conn->flags & (CO_FL_WAIT_WR|CO_FL_WAIT_DATA))) conn->app_cb->send(conn); if (unlikely(conn->flags & CO_FL_ERROR))