Reindent server/core/session.c

This commit is contained in:
Johan Wikman
2015-11-30 19:59:34 +02:00
parent 8601068dc2
commit 15df33a93f
2 changed files with 638 additions and 630 deletions

View File

@ -152,7 +152,6 @@ session_alloc(SERVICE *service, DCB *client_dcb)
pthread_self(), pthread_self(),
__func__, __func__,
service->name); service->name);
} }
/* /*
* Pending filter chain being setup set the head of the chain to * Pending filter chain being setup set the head of the chain to
@ -316,8 +315,7 @@ session_link_dcb(SESSION *session, DCB *dcb)
return true; return true;
} }
int session_unlink_dcb( int session_unlink_dcb(SESSION* session,
SESSION* session,
DCB* dcb) DCB* dcb)
{ {
int nlink; int nlink;
@ -386,7 +384,6 @@ session_simple_free(SESSION *session, DCB *dcb)
free(session); free(session);
} }
/** /**
* Deallocate the specified session * Deallocate the specified session
* *
@ -440,8 +437,7 @@ session_free(SESSION *session)
*/ */
if (!session->ses_is_child && session->router_session) if (!session->ses_is_child && session->router_session)
{ {
session->service->router->freeSession( session->service->router->freeSession(session->service->router_instance,
session->service->router_instance,
session->router_session); session->router_session);
} }
if (session->n_filters) if (session->n_filters)
@ -450,17 +446,19 @@ session_free(SESSION *session)
for (i = 0; i < session->n_filters; i++) for (i = 0; i < session->n_filters; i++)
{ {
if (session->filters[i].filter) if (session->filters[i].filter)
session->filters[i].filter->obj->closeSession( {
session->filters[i].instance, session->filters[i].filter->obj->closeSession(session->filters[i].instance,
session->filters[i].session); session->filters[i].session);
} }
}
for (i = 0; i < session->n_filters; i++) for (i = 0; i < session->n_filters; i++)
{ {
if (session->filters[i].filter) if (session->filters[i].filter)
session->filters[i].filter->obj->freeSession( {
session->filters[i].instance, session->filters[i].filter->obj->freeSession(session->filters[i].instance,
session->filters[i].session); session->filters[i].session);
} }
}
free(session->filters); free(session->filters);
} }
@ -589,7 +587,9 @@ int norouter = 0;
} }
spinlock_release(&session_spin); spinlock_release(&session_spin);
if (noclients) if (noclients)
{
printf("%d Sessions have no clients\n", noclients); printf("%d Sessions have no clients\n", noclients);
}
spinlock_acquire(&session_spin); spinlock_acquire(&session_spin);
ptr = allSessions; ptr = allSessions;
while (ptr) while (ptr)
@ -612,8 +612,10 @@ int norouter = 0;
} }
spinlock_release(&session_spin); spinlock_release(&session_spin);
if (norouter) if (norouter)
{
printf("%d Sessions have no router session\n", norouter); printf("%d Sessions have no router session\n", norouter);
} }
}
/** /**
* Print all sessions to a DCB * Print all sessions to a DCB
@ -634,7 +636,6 @@ SESSION *ptr;
ptr = allSessions; ptr = allSessions;
while (ptr) while (ptr)
{ {
dcb_printf(dcb, "Session %d (%p)\n",ptr->ses_id, ptr); dcb_printf(dcb, "Session %d (%p)\n",ptr->ses_id, ptr);
dcb_printf(dcb, "\tState: %s\n", session_state(ptr->state)); dcb_printf(dcb, "\tState: %s\n", session_state(ptr->state));
dcb_printf(dcb, "\tService: %s (%p)\n", ptr->service->name, ptr->service); dcb_printf(dcb, "\tService: %s (%p)\n", ptr->service->name, ptr->service);
@ -679,7 +680,6 @@ struct tm result;
char buf[30]; char buf[30];
int i; int i;
dcb_printf(dcb, "Session %d (%p)\n",ptr->ses_id, ptr); dcb_printf(dcb, "Session %d (%p)\n",ptr->ses_id, ptr);
dcb_printf(dcb, "\tState: %s\n", session_state(ptr->state)); dcb_printf(dcb, "\tState: %s\n", session_state(ptr->state));
dcb_printf(dcb, "\tService: %s (%p)\n", ptr->service->name, ptr->service); dcb_printf(dcb, "\tService: %s (%p)\n", ptr->service->name, ptr->service);
@ -706,8 +706,7 @@ int i;
{ {
dcb_printf(dcb, "\tFilter: %s\n", dcb_printf(dcb, "\tFilter: %s\n",
ptr->filters[i].filter->name); ptr->filters[i].filter->name);
ptr->filters[i].filter->obj->diagnostics( ptr->filters[i].filter->obj->diagnostics(ptr->filters[i].instance,
ptr->filters[i].instance,
ptr->filters[i].session, ptr->filters[i].session,
dcb); dcb);
} }
@ -747,7 +746,10 @@ SESSION *ptr;
ptr = ptr->next; ptr = ptr->next;
} }
if (allSessions) if (allSessions)
dcb_printf(dcb, "-----------------+-----------------+----------------+--------------------------\n\n"); {
dcb_printf(dcb,
"-----------------+-----------------+----------------+--------------------------\n\n");
}
spinlock_release(&session_spin); spinlock_release(&session_spin);
} }
@ -781,20 +783,20 @@ session_state(int state)
return "Session to be freed"; return "Session to be freed";
case SESSION_STATE_FREE: case SESSION_STATE_FREE:
return "Freed session"; return "Freed session";
#endif #endif
default: default:
return "Invalid State"; return "Invalid State";
} }
} }
SESSION* get_session_by_router_ses( SESSION* get_session_by_router_ses(void* rses)
void* rses)
{ {
SESSION* ses = allSessions; SESSION* ses = allSessions;
while (ses->router_session != rses && ses->next != NULL) while (ses->router_session != rses && ses->next != NULL)
{
ses = ses->next; ses = ses->next;
}
if (ses->router_session != rses) if (ses->router_session != rses)
{ {
@ -907,13 +909,13 @@ char *
session_get_remote(SESSION *session) session_get_remote(SESSION *session)
{ {
if (session && session->client) if (session && session->client)
{
return session->client->remote; return session->client->remote;
}
return NULL; return NULL;
} }
bool session_route_query ( bool session_route_query(SESSION* ses, GWBUF* buf)
SESSION* ses,
GWBUF* buf)
{ {
bool succp; bool succp;
@ -987,14 +989,14 @@ void session_close_timeouts(void* data)
spinlock_acquire(&session_spin); spinlock_acquire(&session_spin);
ses = ses->next; ses = ses->next;
spinlock_release(&session_spin); spinlock_release(&session_spin);
} }
} }
/** /**
* Callback structure for the session list extraction * Callback structure for the session list extraction
*/ */
typedef struct { typedef struct
{
int index; int index;
SESSIONLISTFILTER filter; SESSIONLISTFILTER filter;
} SESSIONFILTER; } SESSIONFILTER;
@ -1074,7 +1076,9 @@ RESULTSET *set;
SESSIONFILTER *data; SESSIONFILTER *data;
if ((data = (SESSIONFILTER *)malloc(sizeof(SESSIONFILTER))) == NULL) if ((data = (SESSIONFILTER *)malloc(sizeof(SESSIONFILTER))) == NULL)
{
return NULL; return NULL;
}
data->index = 0; data->index = 0;
data->filter = filter; data->filter = filter;
if ((set = resultset_create(sessionRowCallback, data)) == NULL) if ((set = resultset_create(sessionRowCallback, data)) == NULL)

View File

@ -52,11 +52,13 @@ struct filter_def;
/** /**
* The session statistics structure * The session statistics structure
*/ */
typedef struct { typedef struct
{
time_t connect; /**< Time when the session was started */ time_t connect; /**< Time when the session was started */
} SESSION_STATS; } SESSION_STATS;
typedef enum { typedef enum
{
SESSION_STATE_ALLOC, /*< for all sessions */ SESSION_STATE_ALLOC, /*< for all sessions */
SESSION_STATE_READY, /*< for router session */ SESSION_STATE_READY, /*< for router session */
SESSION_STATE_ROUTER_READY, /*< for router session */ SESSION_STATE_ROUTER_READY, /*< for router session */
@ -72,22 +74,22 @@ typedef enum {
* The downstream element in the filter chain. This may refer to * The downstream element in the filter chain. This may refer to
* another filter or to a router. * another filter or to a router.
*/ */
typedef struct { typedef struct
{
void *instance; void *instance;
void *session; void *session;
int (*routeQuery)(void *instance, void *session, int (*routeQuery)(void *instance, void *session, GWBUF *request);
GWBUF *request);
} DOWNSTREAM; } DOWNSTREAM;
/** /**
* The upstream element in the filter chain. This may refer to * The upstream element in the filter chain. This may refer to
* another filter or to the protocol implementation. * another filter or to the protocol implementation.
*/ */
typedef struct { typedef struct
{
void *instance; void *instance;
void *session; void *session;
int (*clientReply)(void *instance, int (*clientReply)(void *instance, void *session, GWBUF *response);
void *session, GWBUF *response);
int (*error)(void *instance, void *session, void *); int (*error)(void *instance, void *session, void *);
} UPSTREAM; } UPSTREAM;
@ -95,9 +97,9 @@ typedef struct {
* Structure used to track the filter instances and sessions of the filters * Structure used to track the filter instances and sessions of the filters
* that are in use within a session. * that are in use within a session.
*/ */
typedef struct { typedef struct
struct filter_def {
*filter; struct filter_def *filter;
void *instance; void *instance;
void *session; void *session;
} SESSION_FILTER; } SESSION_FILTER;
@ -105,7 +107,8 @@ typedef struct {
/** /**
* Filter type for the sessionGetList call * Filter type for the sessionGetList call
*/ */
typedef enum { typedef enum
{
SESSION_LIST_ALL, SESSION_LIST_ALL,
SESSION_LIST_CONNECTION SESSION_LIST_CONNECTION
} SESSIONLISTFILTER; } SESSIONLISTFILTER;
@ -117,7 +120,8 @@ typedef enum {
* to the database, it links the descriptors, routing implementation * to the database, it links the descriptors, routing implementation
* and originating service together for the client session. * and originating service together for the client session.
*/ */
typedef struct session { typedef struct session
{
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_chk_t ses_chk_top; skygw_chk_t ses_chk_top;
#endif #endif