]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add conn_init() to (re)initialize a connection
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Oct 2013 15:10:08 +0000 (17:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2013 14:40:23 +0000 (15:40 +0100)
This function will ease the initialization of new connections as well
as their reuse. It initializes the obj_type and a few fields so that
the connection is fresh again. It leaves the addresses and target
untouched so it is suitable for use across connection retries.

include/proto/connection.h

index aa887694e4d1727b0f5f62d8a087956f92fb5fc9..bd3e890f1fb65f14f45972f21f78d7c57b9fdc25 100644 (file)
@@ -425,6 +425,24 @@ static inline int conn_sock_shutw_pending(struct connection *c)
        return (c->flags & (CO_FL_DATA_WR_SH | CO_FL_SOCK_WR_SH)) == CO_FL_DATA_WR_SH;
 }
 
+/* Initializes all required fields for a new connection. Note that it does the
+ * minimum acceptable initialization for a connection that already exists and
+ * is about to be reused. It also leaves the addresses untouched, which makes
+ * it usable across connection retries to reset a connection to a known state.
+ */
+static inline void conn_init(struct connection *conn)
+{
+       conn->obj_type = OBJ_TYPE_CONN;
+       conn->flags = CO_FL_NONE;
+       conn->xprt_st = 0;
+       conn->xprt_ctx = NULL;
+       conn->data = NULL;
+       conn->owner = NULL;
+       conn->t.sock.fd = -1; /* just to help with debugging */
+       conn->err_code = CO_ER_NONE;
+       conn->target = NULL;
+}
+
 /* Retrieves the connection's source address */
 static inline void conn_get_from_addr(struct connection *conn)
 {