]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: use the control layer's init/close
authorWilly Tarreau <w@1wt.eu>
Tue, 8 Dec 2020 14:53:45 +0000 (15:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 Dec 2020 14:53:45 +0000 (15:53 +0100)
In conn_ctrl_init() and conn_ctrl_close() we now use the control layer's
functions instead of manipulating the FD directly. This is safe since the
control layer is always present when done. Note that now we also adjust
the flag before calling the function to make things cleaner in case such
a layer would need to call the same functions again for any reason.

include/haproxy/connection.h

index 9b89d6e420b6b5c236c7ffbba071de9dd9006be2..776a4cb5109d96c59a7c4fd4adc4c513d7ffefc0 100644 (file)
@@ -124,29 +124,29 @@ static inline void conn_xprt_close(struct connection *conn)
 }
 
 /* Initializes the connection's control layer which essentially consists in
- * registering the file descriptor for polling and setting the CO_FL_CTRL_READY
- * flag. The caller is responsible for ensuring that the control layer is
- * already assigned to the connection prior to the call.
+ * registering the connection handle (e.g. file descriptor) for events and
+ * setting the CO_FL_CTRL_READY flag. The caller is responsible for ensuring
+ * that the control layer is already assigned to the connection prior to the
+ * call.
  */
 static inline void conn_ctrl_init(struct connection *conn)
 {
        if (!conn_ctrl_ready(conn)) {
-               int fd = conn->handle.fd;
-
-               fd_insert(fd, conn, conn_fd_handler, tid_bit);
                conn->flags |= CO_FL_CTRL_READY;
+               if (conn->ctrl->ctrl_init)
+                       conn->ctrl->ctrl_init(conn);
        }
 }
 
-/* Deletes the FD if the transport layer is already gone. Once done,
- * it then removes the CO_FL_CTRL_READY flag.
+/* Deletes the connection's handle (e.g. FD) if the transport layer is already
+ * gone, and removes the CO_FL_CTRL_READY flag.
  */
 static inline void conn_ctrl_close(struct connection *conn)
 {
        if ((conn->flags & (CO_FL_XPRT_READY|CO_FL_CTRL_READY)) == CO_FL_CTRL_READY) {
-               fd_delete(conn->handle.fd);
-               conn->handle.fd = DEAD_FD_MAGIC;
                conn->flags &= ~CO_FL_CTRL_READY;
+               if (conn->ctrl->ctrl_close)
+                       conn->ctrl->ctrl_close(conn);
        }
 }