From cbcf77edb74ec52fde20d026c57429dc4c041fec Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 27 Dec 2019 14:49:19 +0100 Subject: [PATCH] MINOR: connection: remove the double test on xprt_done_cb() The conn_fd_handler used to have one possible call to this function to notify about end of handshakes, and another one to notify about connection setup or error. But given that we're now only performing wakeup calls after connection validation, we don't need to keep two places to run this test since the conditions do not change in between. This patch merges the two tests into a single one and moves the CO_FL_CONNECTED test appropriately as well so that it's called even on the error path if needed. --- src/connection.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/connection.c b/src/connection.c index c0aac0aaa..82890f9b1 100644 --- a/src/connection.c +++ b/src/connection.c @@ -71,21 +71,6 @@ void conn_fd_handler(int fd) goto leave; } - /* Verify if the connection just established. */ - if (unlikely(!(conn->flags & (CO_FL_WAIT_L4_CONN | CO_FL_WAIT_L6_CONN | CO_FL_CONNECTED)))) - conn->flags |= CO_FL_CONNECTED; - - /* The connection owner might want to be notified about an end of - * handshake indicating the connection is ready, before we proceed with - * any data exchange. The callback may fail and cause the connection to - * be destroyed, thus we must not use it anymore and should immediately - * leave instead. The caller must immediately unregister itself once - * called. - */ - if (!(conn->flags & CO_FL_HANDSHAKE) && - conn->xprt_done_cb && conn->xprt_done_cb(conn) < 0) - return; - if (fd_send_ready(fd) && fd_send_active(fd)) { /* force reporting of activity by clearing the previous flags : * we'll have at least ERROR or CONNECTED at the end of an I/O, @@ -121,14 +106,20 @@ void conn_fd_handler(int fd) } leave: - /* The connection owner might want to be notified about failures to - * complete the handshake. The callback may fail and cause the + /* Verify if the connection just established. */ + if (unlikely(!(conn->flags & (CO_FL_WAIT_L4_CONN | CO_FL_WAIT_L6_CONN | CO_FL_CONNECTED)))) + conn->flags |= CO_FL_CONNECTED; + + /* The connection owner might want to be notified about failures + * and/or handshake completeion. The callback may fail and cause the * connection to be destroyed, thus we must not use it anymore and * should immediately leave instead. The caller must immediately * unregister itself once called. */ - if (((conn->flags ^ flags) & CO_FL_NOTIFY_DONE) && - conn->xprt_done_cb && conn->xprt_done_cb(conn) < 0) + if (unlikely(conn->xprt_done_cb) && + (!(conn->flags & CO_FL_HANDSHAKE) || + ((conn->flags ^ flags) & CO_FL_NOTIFY_DONE)) && + conn->xprt_done_cb(conn) < 0) return; /* The wake callback is normally used to notify the data layer about