From: Willy Tarreau Date: Mon, 14 Oct 2013 15:10:08 +0000 (+0200) Subject: MINOR: connection: add conn_init() to (re)initialize a connection X-Git-Tag: v1.5-dev20~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d015577428dee5aabac5aa3517702dc08480d353;p=thirdparty%2Fhaproxy.git MINOR: connection: add conn_init() to (re)initialize a connection 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. --- diff --git a/include/proto/connection.h b/include/proto/connection.h index aa887694e4..bd3e890f1f 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -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) {