]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: introduce session_new()
authorWilly Tarreau <w@1wt.eu>
Sat, 4 Apr 2015 22:38:48 +0000 (00:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Apr 2015 09:37:33 +0000 (11:37 +0200)
This one creates a new session and does the minimum initialization.

include/proto/session.h
src/session.c

index 3f008e16e36a87a5f98b5df684a704ca1489072e..cb4deeceb5db6e88ede9f167963c4d6bb160195f 100644 (file)
@@ -33,6 +33,7 @@
 #include <proto/stick_table.h>
 
 extern struct pool_head *pool2_session;
+struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type *origin);
 void session_free(struct session *sess);
 int init_session();
 int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr);
index 070c340b89feffa1e374f9411131e1b445abcac7..5580d4f3dd4b43681e17d282a28cbf7b33a4631b 100644 (file)
@@ -42,6 +42,27 @@ struct data_cb sess_conn_cb = {
        .init = conn_complete_session,
 };
 
+/* Create a a new session and assign it to frontend <fe>, listener <li>,
+ * origin <origin>, set the current date and clear the stick counters pointers.
+ * Returns the session upon success or NULL. The session may be released using
+ * session_free().
+ */
+struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type *origin)
+{
+       struct session *sess;
+
+       sess = pool_alloc2(pool2_session);
+       if (sess) {
+               sess->listener = li;
+               sess->fe = fe;
+               sess->origin = origin;
+               sess->accept_date = date; /* user-visible date for logging */
+               sess->tv_accept   = now;  /* corrected date for internal use */
+               memset(sess->stkctr, 0, sizeof(sess->stkctr));
+       }
+       return sess;
+}
+
 void session_free(struct session *sess)
 {
        session_store_counters(sess);