From 4a6689b7683d1dec50e1c45c050fc90990ec4794 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 20 Apr 2010 14:24:28 +0200 Subject: [PATCH] Client list for session to separate client_list --- src/client.c | 35 ----------------------------------- src/session.c | 46 ++++++++++++++++++++++++++++++++-------------- src/session.h | 4 +++- 3 files changed, 35 insertions(+), 50 deletions(-) diff --git a/src/client.c b/src/client.c index a2fce08..a9f2406 100644 --- a/src/client.c +++ b/src/client.c @@ -99,7 +99,6 @@ struct client { int diagnostic; enum client_state state; struct show_raw *show_raw; - struct client *next; // next client in session or next in free list ZOOM_resultset resultset; YAZ_MUTEX mutex; int ref_count; @@ -615,7 +614,6 @@ struct client *client_create(void) r->state = Client_Disconnected; r->show_raw = 0; r->resultset = 0; - r->next = 0; r->mutex = 0; pazpar2_mutex_create(&r->mutex, "client"); @@ -640,7 +638,6 @@ int client_destroy(struct client *c) c, client_get_url(c), c->ref_count); if (!pazpar2_decref(&c->ref_count, c->mutex)) { - c->next = 0; xfree(c->pquery); c->pquery = 0; xfree(c->cqlquery); @@ -822,33 +819,9 @@ int client_parse_query(struct client *cl, const char *query) return 0; } - -void client_remove_from_session(struct client *c) -{ - struct session *se; - - se = c->session; - assert(se); - if (se) - { - struct client **ccp = &se->clients; - - while (*ccp && *ccp != c) - ccp = &(*ccp)->next; - assert(*ccp == c); - *ccp = c->next; - - c->database = 0; - c->session = 0; - c->next = 0; - } -} - void client_set_session(struct client *cl, struct session *se) { cl->session = se; - cl->next = se->clients; - se->clients = cl; } int client_is_active(struct client *cl) @@ -859,14 +832,6 @@ int client_is_active(struct client *cl) return 0; } -struct client *client_next_in_session(struct client *cl) -{ - if (cl) - return cl->next; - return 0; - -} - Odr_int client_get_hits(struct client *cl) { return cl->hits; diff --git a/src/session.c b/src/session.c index 33331fb..aad56ea 100644 --- a/src/session.c +++ b/src/session.c @@ -81,6 +81,11 @@ struct parameters global_parameters = 0 // debug_mode }; +struct client_list { + struct client *client; + struct client_list *next; +}; + static void log_xml_doc(xmlDoc *doc) { FILE *lf = yaz_log_file(); @@ -445,18 +450,28 @@ static void select_targets_callback(void *context, struct session_database *db) { struct session *se = (struct session*) context; struct client *cl = client_create(); + struct client_list *l; client_set_database(cl, db); + client_set_session(cl, se); + l = xmalloc(sizeof(*l)); + l->client = cl; + l->next = se->clients; + se->clients = l; } static void session_remove_clients(struct session *se) { - while (se->clients) + struct client_list *l = se->clients; + while (l) { - struct client *cl = se->clients; - client_remove_from_session(cl); - client_destroy(cl); + struct client_list *l_next = l->next; + client_set_session(l->client, 0); + client_destroy(l->client); + xfree(l); + l = l_next; } + se->clients = 0; } // Associates a set of clients with a session; @@ -470,11 +485,11 @@ static int select_targets(struct session *se, const char *filter) int session_active_clients(struct session *s) { - struct client *c; + struct client_list *l; int res = 0; - for (c = s->clients; c; c = client_next_in_session(c)) - if (client_is_active(c)) + for (l = s->clients; l; l = l->next) + if (client_is_active(l->client)) res++; return res; @@ -490,7 +505,7 @@ enum pazpar2_error_code search(struct session *se, int live_channels = 0; int no_working = 0; int no_failed = 0; - struct client *cl; + struct client_list *l; yaz_log(YLOG_DEBUG, "Search"); @@ -511,8 +526,9 @@ enum pazpar2_error_code search(struct session *se, } se->reclist = reclist_create(se->nmem); - for (cl = se->clients; cl; cl = client_next_in_session(cl)) + for (l = se->clients; l; l = l->next) { + struct client *cl = l->client; if (maxrecs) client_set_maxrecs(cl, atoi(maxrecs)); if (startrecs) @@ -694,17 +710,18 @@ struct session *new_session(NMEM nmem, struct conf_service *service, struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem) { struct hitsbytarget *res = 0; - struct client *cl; + struct client_list *l; size_t sz = 0; session_enter(se); - for (cl = se->clients; cl; cl = client_next_in_session(cl)) + for (l = se->clients; l; l = l->next) sz++; res = nmem_malloc(nmem, sizeof(*res) * sz); *count = 0; - for (cl = se->clients; cl; cl = client_next_in_session(cl)) + for (l = se->clients; l; l = l->next) { + struct client *cl = l->client; WRBUF w = wrbuf_alloc(); const char *name = session_setting_oneval(client_get_database(cl), PZ_NAME); @@ -854,12 +871,13 @@ void show_range_stop(struct session *s, struct record_cluster **recs) void statistics(struct session *se, struct statistics *stat) { - struct client *cl; + struct client_list *l; int count = 0; memset(stat, 0, sizeof(*stat)); - for (cl = se->clients; cl; cl = client_next_in_session(cl)) + for (l = se->clients; l; l = l->next) { + struct client *cl = l->client; if (!client_get_connection(cl)) stat->num_no_connection++; switch (client_get_state(cl)) diff --git a/src/session.h b/src/session.h index 76a03a2..0bafe72 100644 --- a/src/session.h +++ b/src/session.h @@ -97,11 +97,13 @@ struct session_watchentry { session_watchfun fun; }; +struct client_list; + // End-user session struct session { struct conf_service *service; /* service in use for this session */ struct session_database *databases; // All databases, settings overriden - struct client *clients; // Clients connected for current search + struct client_list *clients; // Clients connected for current search NMEM session_nmem; // Nmem for session-permanent storage NMEM nmem; // Nmem for each operation (i.e. search, result set, etc) WRBUF wrbuf; // Wrbuf for scratch(i.e. search) -- 1.7.10.4