]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add conn_fd() to retrieve the FD only when it exists
authorWilly Tarreau <w@1wt.eu>
Mon, 11 Apr 2022 15:54:46 +0000 (17:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 Apr 2022 17:31:47 +0000 (19:31 +0200)
There are plenty of places (particularly in debug code) where we try to
dump the connection's FD only when the connection is defined. That's
already a pain but now it gets one step further with QUIC because we do
*not* want to dump this FD in this case.

conn_fd() checks if the connection exists, is ready and is not fd-less,
and returns the FD only in this case, otherwise returns -1. This aims at
simplifying most of these conditions.

include/haproxy/connection.h

index 5ce13899a761fe8b6bd7b15644563edbceb238de..f6407ff4b21ec5fac6bd590e6daf4022973c326e 100644 (file)
@@ -200,6 +200,16 @@ static inline void conn_stop_tracking(struct connection *conn)
        conn->flags &= ~CO_FL_XPRT_TRACKED;
 }
 
+/* returns the connection's FD if the connection exists, its control is ready,
+ * and the connection has an FD, otherwise -1.
+ */
+static inline int conn_fd(const struct connection *conn)
+{
+       if (!conn || !conn_ctrl_ready(conn) || (conn->flags & CO_FL_FDLESS))
+               return -1;
+       return conn->handle.fd;
+}
+
 /* read shutdown, called from the rcv_buf/rcv_pipe handlers when
  * detecting an end of connection.
  */