]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add conn_new() / conn_free()
authorWilly Tarreau <w@1wt.eu>
Sun, 20 Oct 2013 20:56:45 +0000 (22:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2013 14:40:23 +0000 (15:40 +0100)
conn_new() will be a more convenient way of allocating and initializing
a connection. It calls pool_alloc2() and conn_init() upon success.

conn_free() is just a pool_free2() but is provided for symmetry with
conn_new().

include/proto/connection.h

index a552a043803b36c4d0e3c70e94c97e523eb39d4a..21d57c986f1e9f0cb1feb0326d2817774901dac4 100644 (file)
@@ -443,6 +443,27 @@ static inline void conn_init(struct connection *conn)
        conn->target = NULL;
 }
 
+/* Tries to allocate a new connection and initialized its main fields. The
+ * connection is returned on success, NULL on failure. The connection must
+ * be released using pool_free2() or conn_free().
+ */
+static inline struct connection *conn_new()
+{
+       struct connection *conn;
+
+       conn = pool_alloc2(pool2_connection);
+       if (likely(conn != NULL))
+               conn_init(conn);
+       return conn;
+}
+
+/* Releases a connection previously allocated by conn_new() */
+static inline void conn_free(struct connection *conn)
+{
+       pool_free2(pool2_connection, conn);
+}
+
+
 /* Retrieves the connection's source address */
 static inline void conn_get_from_addr(struct connection *conn)
 {