MySQL 8.1.0
Source Code Documentation
service_srv_session.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22#ifndef MYSQL_SRV_SESSION_SERVICE_INCLUDED
23#define MYSQL_SRV_SESSION_SERVICE_INCLUDED
24
25/**
26 @file include/mysql/service_srv_session.h
27 Header file for the Server session service. This service is to provide
28 of creating sessions with the server. These sessions can be furtherly used
29 together with the Command service to execute commands in the server.
30
31 @note Session should not be used after being closed, unless MYSQL_SESSION
32 handle is set to NULL.
33*/
34
35#include "mysql/service_srv_session_bits.h" /* MYSQL_SESSION, srv_session_error_cb */
36
37#ifndef MYSQL_ABI_CHECK
38#include "mysql/plugin.h" /* MYSQL_THD */
39#endif
40
41extern "C" struct srv_session_service_st {
42 int (*init_session_thread)(const void *plugin);
43
45
46 MYSQL_SESSION(*open_session)
48
50
52
54
55 int (*attach_session)(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd);
57
58#ifdef MYSQL_DYNAMIC_PLUGIN
59
60#define srv_session_init_thread(plugin) \
61 srv_session_service->init_session_thread((plugin))
62
63#define srv_session_deinit_thread() srv_session_service->deinit_session_thread()
64
65#define srv_session_open(cb, ctx) srv_session_service->open_session((cb), (ctx))
66
67#define srv_session_detach(session) \
68 srv_session_service->detach_session((session))
69
70#define srv_session_close(session) srv_session_service->close_session((session))
71
72#define srv_session_server_is_available() \
73 srv_session_service->server_is_available()
74
75#define srv_session_attach(session, thd) \
76 srv_session_service->attach_session((session), (thd))
77
78#else
79
80/**
81 Initializes the current physical thread to use with session service.
82
83 Call this function ONLY in physical threads which are not initialized in
84 any way by the server.
85
86 @param plugin Pointer to the plugin structure, passed to the plugin over
87 the plugin init function.
88
89 @return
90 0 success
91 1 failure
92*/
93int srv_session_init_thread(const void *plugin);
94
95/**
96 Deinitializes the current physical thread to use with session service.
97
98
99 Call this function ONLY in physical threads which were initialized using
100 srv_session_init_thread().
101*/
103
104/**
105 Opens a server session.
106
107 In a thread not initialized by the server itself, this function should be
108 called only after srv_session_init_thread() has already been called.
109
110 @param error_cb session error callback
111 @param plugin_ctx Plugin's context, opaque pointer that would
112 be provided to callbacks. Might be NULL.
113 @return
114 session on success
115 NULL on failure
116*/
117MYSQL_SESSION srv_session_open(srv_session_error_cb error_cb, void *plugin_ctx);
118
119/**
120 Detaches a session from current physical thread.
121
122 Detaches a previously session. Which can only occur when the MYSQL_SESSION
123 was manually attached by "srv_session_attach".
124 Other srv_session calls automatically attached/detached the THD when the
125 MYSQL_SESSION is used (for example command_service_run_command()).
126
127 @param session Session to detach
128
129 @returns
130 0 success
131 1 failure
132*/
134
135/**
136 Closes a previously opened session.
137
138 @param session Session to close
139
140 @note This method close the session but session handle is not set to NULL.
141 Session handle should be set to NULL explicitly after calling this
142 method. Session should not be used otherwise.
143
144 @return
145 0 success
146 1 failure
147*/
149
150/**
151 Returns if the server is available (not booting or shutting down)
152
153 @return
154 0 not available
155 1 available
156*/
158
159/**
160 Attaches a session to current physical thread.
161
162 Previously attached THD is detached and returned through ret_previous_thd.
163 THD associated with session is attached.
164
165 @param session Session to attach
166 @param ret_previous_thd Previously attached THD
167
168 @returns
169 0 success
170 1 failure
171*/
172int srv_session_attach(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd);
173
174#endif
175
176#endif /* MYSQL_SRV_SESSION_SERVICE_INCLUDED */
#define MYSQL_THD
Definition: backup_page_tracker.h:37
int srv_session_init_thread(const void *plugin)
Initializes the current physical thread to use with session service.
Definition: srv_session_service.cc:59
struct srv_session_service_st * srv_session_service
int srv_session_attach(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd)
Attaches a session to current physical thread.
Definition: srv_session_service.cc:231
void srv_session_deinit_thread()
Deinitializes the current physical thread to use with session service.
Definition: srv_session_service.cc:66
int srv_session_server_is_available()
Returns if the server is available (not booting or shutting down)
Definition: srv_session_service.cc:220
int srv_session_close(MYSQL_SESSION session)
Closes a previously opened session.
MYSQL_SESSION srv_session_open(srv_session_error_cb error_cb, void *plugin_ctx)
Opens a server session.
Definition: srv_session_service.cc:144
int srv_session_detach(MYSQL_SESSION session)
Detaches a session from current physical thread.
These are the common definitions between the plugin service for sessions and the component service ex...
class Srv_session * MYSQL_SESSION
Definition: service_srv_session_bits.h:36
void(* srv_session_error_cb)(void *ctx, unsigned int sql_errno, const char *err_msg)
Definition: service_srv_session_bits.h:42
Definition: service_srv_session.h:41
srv_session_error_cb void * plugix_ctx
Definition: service_srv_session.h:47
srv_session_error_cb error_cb
Definition: service_srv_session.h:47
int(* attach_session)(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd)
Definition: service_srv_session.h:55
int(* server_is_available)()
Definition: service_srv_session.h:53
void(* deinit_session_thread)()
Definition: service_srv_session.h:44
int(* init_session_thread)(const void *plugin)
Definition: service_srv_session.h:42
int(* close_session)(MYSQL_SESSION session)
Definition: service_srv_session.h:51
int(* detach_session)(MYSQL_SESSION session)
Definition: service_srv_session.h:49