MINOR: session: introduce session_new()

This one creates a new session and does the minimum initialization.
This commit is contained in:
Willy Tarreau 2015-04-05 00:38:48 +02:00
parent d990baf0cc
commit c38f71cfcd
2 changed files with 22 additions and 0 deletions

View 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);

View 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);