From 61a2c960ec152af9eb8f61cf984477e8efaac739 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 30 Aug 2017 10:45:42 +0300 Subject: [PATCH] MXS-1378 Provide access to current session Provide access to current session and session id. This will be used by the logging mechanism for logging the session id together with messages. --- include/maxscale/session.h | 17 +++++++++++++++++ server/core/session.c | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/maxscale/session.h b/include/maxscale/session.h index f55639772..c534a71fb 100644 --- a/include/maxscale/session.h +++ b/include/maxscale/session.h @@ -380,4 +380,21 @@ void session_qualify_for_pool(MXS_SESSION* session); */ bool session_valid_for_pool(const MXS_SESSION* session); +/** + * @brief Return the session of the dcb currently being processed + * by the calling thread. + * + * @return A session, or NULL if the calling thread is not currently handling + * a dcb or if the calling thread is not a polling/worker thread. + **/ +MXS_SESSION* session_get_current(); + +/** + * @brief Return the id of the session of the dcb currently being processed + * by the calling thread. + * + * @return The id of the current session or 0 if there is no current session. + **/ +uint64_t session_get_current_id(); + MXS_END_DECLS diff --git a/server/core/session.c b/server/core/session.c index 87e72c1a7..c194348fb 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -960,3 +960,17 @@ bool session_valid_for_pool(const MXS_SESSION* session) ss_dassert(session->state != SESSION_STATE_DUMMY); return session->qualifies_for_pooling; } + +MXS_SESSION* session_get_current() +{ + DCB* dcb = dcb_get_current(); + + return dcb ? dcb->session : NULL; +} + +uint64_t session_get_current_id() +{ + MXS_SESSION* session = session_get_current(); + + return session ? session->ses_id : 0; +}