Compile server, service and session as C++
This commit is contained in:
parent
ec39b54dea
commit
bb1b7f9755
@ -267,9 +267,9 @@ extern SERVER *server_find_by_unique_name(const char *name);
|
||||
extern int server_find_by_unique_names(char **server_names, int size, SERVER*** output);
|
||||
extern SERVER *server_find(const char *servname, unsigned short port);
|
||||
extern char *server_status(const SERVER *);
|
||||
extern void server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set);
|
||||
extern void server_set_status_nolock(SERVER *server, int bit);
|
||||
extern void server_clear_status_nolock(SERVER *server, int bit);
|
||||
extern void server_clear_set_status(SERVER *server, unsigned specified_bits, unsigned bits_to_set);
|
||||
extern void server_set_status_nolock(SERVER *server, unsigned bit);
|
||||
extern void server_clear_status_nolock(SERVER *server, unsigned bit);
|
||||
extern void server_transfer_status(SERVER *dest_server, const SERVER *source_server);
|
||||
extern void server_add_mon_user(SERVER *server, const char *user, const char *passwd);
|
||||
extern const char *server_get_parameter(const SERVER *server, char *name);
|
||||
|
@ -38,7 +38,7 @@
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
struct server;
|
||||
struct router;
|
||||
struct mxs_router;
|
||||
struct mxs_router_object;
|
||||
struct users;
|
||||
|
||||
@ -126,7 +126,7 @@ typedef struct service
|
||||
char *routerModule; /**< Name of router module to use */
|
||||
char **routerOptions; /**< Router specific option strings */
|
||||
struct mxs_router_object *router; /**< The router we are using */
|
||||
void *router_instance; /**< The router instance for this service */
|
||||
struct mxs_router *router_instance;/**< The router instance for this service */
|
||||
char *version_string; /**< version string for this service listeners */
|
||||
SERVER_REF *dbref; /**< server references */
|
||||
int n_dbref; /**< Number of server references */
|
||||
|
@ -31,6 +31,9 @@ MXS_BEGIN_DECLS
|
||||
struct dcb;
|
||||
struct service;
|
||||
struct mxs_filter_def;
|
||||
struct mxs_filter;
|
||||
struct mxs_filter_session;
|
||||
struct mxs_router_session;
|
||||
struct server;
|
||||
|
||||
typedef enum
|
||||
@ -86,8 +89,8 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
struct mxs_filter_def *filter;
|
||||
void *instance;
|
||||
void *session;
|
||||
struct mxs_filter *instance;
|
||||
struct mxs_filter_session *session;
|
||||
} SESSION_FILTER;
|
||||
|
||||
/**
|
||||
@ -132,7 +135,7 @@ typedef struct session
|
||||
mxs_session_state_t state; /*< Current descriptor state */
|
||||
size_t ses_id; /*< Unique session identifier */
|
||||
struct dcb *client_dcb; /*< The client connection */
|
||||
void *router_session; /*< The router instance data */
|
||||
struct mxs_router_session *router_session; /*< The router instance data */
|
||||
MXS_SESSION_STATS stats; /*< Session statistics */
|
||||
struct service *service; /*< The service this session is using */
|
||||
int n_filters; /*< Number of filter sessions */
|
||||
|
@ -58,7 +58,7 @@ typedef struct ssl_listener
|
||||
SSL_METHOD *method; /*< SSLv3 or TLS1.0/1.1/1.2 methods
|
||||
* see: https://www.openssl.org/docs/ssl/SSL_CTX_new.html */
|
||||
int ssl_cert_verify_depth; /*< SSL certificate verification depth */
|
||||
int ssl_method_type; /*< Which of the SSLv3 or TLS1.0/1.1/1.2 methods to use */
|
||||
ssl_method_type_t ssl_method_type; /*< Which of the SSLv3 or TLS1.0/1.1/1.2 methods to use */
|
||||
char *ssl_cert; /*< SSL certificate */
|
||||
char *ssl_key; /*< SSL private key */
|
||||
char *ssl_ca_cert; /*< SSL CA certificate */
|
||||
|
@ -27,7 +27,9 @@ add_library(maxscale-common SHARED
|
||||
resultset.cc
|
||||
router.cc
|
||||
secrets.cc
|
||||
server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c ssl.c mysql_utils.c mysql_binlog.c modulecmd.c)
|
||||
server.cc
|
||||
service.cc
|
||||
session.cc spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c ssl.c mysql_utils.c mysql_binlog.c modulecmd.c)
|
||||
|
||||
if(WITH_JEMALLOC)
|
||||
target_link_libraries(maxscale-common ${JEMALLOC_LIBRARIES})
|
||||
|
@ -41,7 +41,7 @@ typedef enum
|
||||
} SESSIONLISTFILTER;
|
||||
|
||||
int session_isvalid(MXS_SESSION *);
|
||||
char *session_state(mxs_session_state_t);
|
||||
const char *session_state(mxs_session_state_t);
|
||||
bool session_link_dcb(MXS_SESSION *, struct dcb *);
|
||||
|
||||
RESULTSET *sessionGetList(SESSIONLISTFILTER);
|
||||
|
@ -93,7 +93,7 @@ SERVER* server_alloc(const char *name, const char *address, unsigned short port,
|
||||
char *my_name = MXS_STRDUP(name);
|
||||
char *my_protocol = MXS_STRDUP(protocol);
|
||||
char *my_authenticator = MXS_STRDUP(authenticator);
|
||||
DCB **persistent = MXS_CALLOC(nthr, sizeof(*persistent));
|
||||
DCB **persistent = (DCB**)MXS_CALLOC(nthr, sizeof(*persistent));
|
||||
|
||||
if (!server || !my_name || !my_protocol || !my_authenticator || !persistent)
|
||||
{
|
||||
@ -105,7 +105,7 @@ SERVER* server_alloc(const char *name, const char *address, unsigned short port,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (snprintf(server->name, sizeof(server->name), "%s", address) > sizeof(server->name))
|
||||
if (snprintf(server->name, sizeof(server->name), "%s", address) > (int)sizeof(server->name))
|
||||
{
|
||||
MXS_WARNING("Truncated server address '%s' to the maximum size of %lu characters.",
|
||||
address, sizeof(server->name));
|
||||
@ -313,7 +313,7 @@ int server_find_by_unique_names(char **server_names, int size, SERVER*** output)
|
||||
{
|
||||
ss_dassert(server_names && (size > 0));
|
||||
|
||||
SERVER **results = MXS_CALLOC(size, sizeof(SERVER*));
|
||||
SERVER **results = (SERVER**)MXS_CALLOC(size, sizeof(SERVER*));
|
||||
if (!results)
|
||||
{
|
||||
return 0;
|
||||
@ -765,7 +765,7 @@ server_status(const SERVER *server)
|
||||
* @param bit The bit to set for the server
|
||||
*/
|
||||
void
|
||||
server_set_status_nolock(SERVER *server, int bit)
|
||||
server_set_status_nolock(SERVER *server, unsigned bit)
|
||||
{
|
||||
server->status |= bit;
|
||||
|
||||
@ -786,7 +786,7 @@ server_set_status_nolock(SERVER *server, int bit)
|
||||
* @param bit The bit to set for the server
|
||||
*/
|
||||
void
|
||||
server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set)
|
||||
server_clear_set_status(SERVER *server, unsigned specified_bits, unsigned bits_to_set)
|
||||
{
|
||||
/** clear error logged flag before the next failure */
|
||||
if ((bits_to_set & SERVER_MASTER) && ((server->status & SERVER_MASTER) == 0))
|
||||
@ -807,7 +807,7 @@ server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set)
|
||||
* @param bit The bit to clear for the server
|
||||
*/
|
||||
void
|
||||
server_clear_status_nolock(SERVER *server, int bit)
|
||||
server_clear_status_nolock(SERVER *server, unsigned bit)
|
||||
{
|
||||
server->status &= ~bit;
|
||||
}
|
||||
@ -838,14 +838,14 @@ void
|
||||
server_add_mon_user(SERVER *server, const char *user, const char *passwd)
|
||||
{
|
||||
if (user != server->monuser &&
|
||||
snprintf(server->monuser, sizeof(server->monuser), "%s", user) > sizeof(server->monuser))
|
||||
snprintf(server->monuser, sizeof(server->monuser), "%s", user) > (int)sizeof(server->monuser))
|
||||
{
|
||||
MXS_WARNING("Truncated monitor user for server '%s', maximum username "
|
||||
"length is %lu characters.", server->unique_name, sizeof(server->monuser));
|
||||
}
|
||||
|
||||
if (passwd != server->monpw &&
|
||||
snprintf(server->monpw, sizeof(server->monpw), "%s", passwd) > sizeof(server->monpw))
|
||||
snprintf(server->monpw, sizeof(server->monpw), "%s", passwd) > (int)sizeof(server->monpw))
|
||||
{
|
||||
MXS_WARNING("Truncated monitor password for server '%s', maximum password "
|
||||
"length is %lu characters.", server->unique_name, sizeof(server->monpw));
|
||||
@ -1085,7 +1085,7 @@ server_update_port(SERVER *server, unsigned short port)
|
||||
|
||||
static struct
|
||||
{
|
||||
char *str;
|
||||
const char *str;
|
||||
unsigned int bit;
|
||||
} ServerBits[] =
|
||||
{
|
@ -121,7 +121,7 @@ SERVICE* service_alloc(const char *name, const char *router)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((service->router = load_module(my_router, MODULE_ROUTER)) == NULL)
|
||||
if ((service->router = (MXS_ROUTER_OBJECT*)load_module(my_router, MODULE_ROUTER)) == NULL)
|
||||
{
|
||||
char* home = get_libdir();
|
||||
char* ldpath = getenv("LD_LIBRARY_PATH");
|
||||
@ -441,7 +441,7 @@ static char** copy_string_array(char** original)
|
||||
values++;
|
||||
}
|
||||
|
||||
array = MXS_MALLOC(sizeof(char*) * (values + 1));
|
||||
array = (char**)MXS_MALLOC(sizeof(char*) * (values + 1));
|
||||
|
||||
if (array)
|
||||
{
|
||||
@ -814,7 +814,7 @@ bool serviceHasListener(SERVICE *service, const char *protocol,
|
||||
*/
|
||||
static SERVER_REF* server_ref_create(SERVER *server)
|
||||
{
|
||||
SERVER_REF *sref = MXS_MALLOC(sizeof(SERVER_REF));
|
||||
SERVER_REF *sref = (SERVER_REF*)MXS_MALLOC(sizeof(SERVER_REF));
|
||||
|
||||
if (sref)
|
||||
{
|
||||
@ -1586,11 +1586,11 @@ dListListeners(DCB *dcb)
|
||||
void
|
||||
service_update(SERVICE *service, char *router, char *user, char *auth)
|
||||
{
|
||||
void *router_obj;
|
||||
MXS_ROUTER_OBJECT *router_obj;
|
||||
|
||||
if (!strcmp(service->routerModule, router))
|
||||
{
|
||||
if ((router_obj = load_module(router, MODULE_ROUTER)) == NULL)
|
||||
if ((router_obj = (MXS_ROUTER_OBJECT*)load_module(router, MODULE_ROUTER)) == NULL)
|
||||
{
|
||||
MXS_ERROR("Failed to update router "
|
||||
"for service %s to %s.",
|
@ -48,9 +48,6 @@
|
||||
#include "maxscale/session.h"
|
||||
#include "maxscale/filter.h"
|
||||
|
||||
/* A session with null values, used for initialization */
|
||||
static MXS_SESSION session_initialized = SESSION_INIT;
|
||||
|
||||
/** Global session id; updated safely by use of atomic_add */
|
||||
static int session_id;
|
||||
|
||||
@ -76,19 +73,18 @@ static int session_reply(MXS_FILTER *inst, MXS_FILTER_SESSION *session, GWBUF *d
|
||||
* @brief Initialize a session
|
||||
*
|
||||
* This routine puts initial values into the fields of the session pointed to
|
||||
* by the parameter. The parameter has to be passed as void * because the
|
||||
* function can be called by the generic list manager, which does not know
|
||||
* the actual type of the list entries it handles.
|
||||
*
|
||||
* All fields can be initialized by the assignment of the static
|
||||
* initialized session.
|
||||
* by the parameter.
|
||||
*
|
||||
* @param *session Pointer to the session to be initialized
|
||||
*/
|
||||
static void
|
||||
session_initialize(void *session)
|
||||
session_initialize(MXS_SESSION *session)
|
||||
{
|
||||
*(MXS_SESSION *)session = session_initialized;
|
||||
memset(session, 0, sizeof(MXS_SESSION));
|
||||
|
||||
session->ses_chk_top = CHK_NUM_SESSION;
|
||||
session->state = SESSION_STATE_ALLOC;
|
||||
session->ses_chk_tail = CHK_NUM_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,10 +162,15 @@ session_alloc(SERVICE *service, DCB *client_dcb)
|
||||
* of the chain nearest the router working back to the client
|
||||
* protocol end of the chain.
|
||||
*/
|
||||
session->head.instance = service->router_instance;
|
||||
session->head.session = session->router_session;
|
||||
|
||||
session->head.routeQuery = (void *)(service->router->routeQuery);
|
||||
// NOTE: Here we cast the router instance into a MXS_FILTER and
|
||||
// NOTE: and the router session into a MXS_FILTER_SESSION and
|
||||
// NOTE: the router routeQuery into a filter routeQuery. That
|
||||
// NOTE: is in order to be able to treat the router as the first
|
||||
// NOTE: filter.
|
||||
session->head.instance = (MXS_FILTER*)service->router_instance;
|
||||
session->head.session = (MXS_FILTER_SESSION*)session->router_session;
|
||||
session->head.routeQuery =
|
||||
(int32_t (*)(MXS_FILTER*, MXS_FILTER_SESSION*, GWBUF*))service->router->routeQuery;
|
||||
|
||||
// NOTE: Here we cast the session into a MXS_FILTER and MXS_FILTER_SESSION
|
||||
// NOTE: and session_reply into a filter clientReply. That's dubious but ok
|
||||
@ -326,7 +327,7 @@ void session_close(MXS_SESSION *session)
|
||||
}
|
||||
|
||||
MXS_ROUTER_OBJECT* router = session->service->router;
|
||||
void* router_instance = session->service->router_instance;
|
||||
MXS_ROUTER* router_instance = session->service->router_instance;
|
||||
|
||||
/** Close router session and all its connections */
|
||||
router->closeSession(router_instance, session->router_session);
|
||||
@ -569,7 +570,7 @@ dListSessions(DCB *dcb)
|
||||
* @param state The session state
|
||||
* @return A string representation of the session state
|
||||
*/
|
||||
char *
|
||||
const char *
|
||||
session_state(mxs_session_state_t state)
|
||||
{
|
||||
switch (state)
|
||||
@ -617,8 +618,8 @@ session_setup_filters(MXS_SESSION *session)
|
||||
MXS_UPSTREAM *tail;
|
||||
int i;
|
||||
|
||||
if ((session->filters = MXS_CALLOC(service->n_filters,
|
||||
sizeof(SESSION_FILTER))) == NULL)
|
||||
if ((session->filters = (SESSION_FILTER*)MXS_CALLOC(service->n_filters,
|
||||
sizeof(SESSION_FILTER))) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -897,7 +898,7 @@ static bool ses_find_id(DCB *dcb, void *data)
|
||||
{
|
||||
void **params = (void**)data;
|
||||
MXS_SESSION **ses = (MXS_SESSION**)params[0];
|
||||
int *id = (int*)params[1];
|
||||
size_t *id = (size_t*)params[1];
|
||||
bool rval = true;
|
||||
|
||||
if (dcb->session->ses_id == *id)
|
@ -40,7 +40,7 @@
|
||||
|
||||
// This is pretty ugly but it's required to test internal functions
|
||||
#include "../config.cc"
|
||||
#include "../server.c"
|
||||
#include "../server.cc"
|
||||
|
||||
/**
|
||||
* test1 Allocate a server and do lots of other things
|
||||
|
@ -105,13 +105,13 @@ bool avro_handle_convert(const MODULECMD_ARG *args)
|
||||
bool rval = false;
|
||||
|
||||
if (strcmp(args->argv[1].value.string, "start") == 0 &&
|
||||
conversion_task_ctl(args->argv[0].value.service->router_instance, true))
|
||||
conversion_task_ctl((AVRO_INSTANCE*)args->argv[0].value.service->router_instance, true))
|
||||
{
|
||||
MXS_NOTICE("Started conversion for service '%s'.", args->argv[0].value.service->name);
|
||||
rval = true;
|
||||
}
|
||||
else if (strcmp(args->argv[1].value.string, "stop") == 0 &&
|
||||
conversion_task_ctl(args->argv[0].value.service->router_instance, false))
|
||||
conversion_task_ctl((AVRO_INSTANCE*)args->argv[0].value.service->router_instance, false))
|
||||
{
|
||||
MXS_NOTICE("Stopped conversion for service '%s'.", args->argv[0].value.service->name);
|
||||
rval = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user