From f7fb437044f32ea7e85a114414f32b170ab0ebb0 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Thu, 14 Dec 2006 14:58:03 +0000 Subject: [PATCH] Part of the way to blocking functions Fixes bug on timeout of sessions --- pazpar2.c | 20 +++++++++++++++++--- pazpar2.h | 10 ++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pazpar2.c b/pazpar2.c index f953a7d..55dabb2 100644 --- a/pazpar2.c +++ b/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.12 2006-12-12 02:36:24 quinn Exp $ */; +/* $Id: pazpar2.c,v 1.13 2006-12-14 14:58:03 quinn Exp $ */; #include #include @@ -736,12 +736,14 @@ static void handler(IOCHAN i, int event) if (len < 0) { - client_fatal(cl); + yaz_log(YLOG_WARN|YLOG_ERRNO, "Error reading from Z server"); + connection_destroy(co); return; } else if (len == 0) { - client_fatal(cl); + yaz_log(YLOG_WARN, "EOF reading from Z server"); + connection_destroy(co); return; } else if (len > 1) // We discard input if we have no connection @@ -1113,6 +1115,12 @@ void client_destroy(struct client *c) client_freelist = c; } +void session_set_watch(struct session *s, int what, session_watchfun fun, void *data) +{ + s->watchlist[what].fun = fun; + s->watchlist[what].data = data; +} + // This should be extended with parameters to control selection criteria // Associates a set of clients with a session; int select_targets(struct session *se) @@ -1180,6 +1188,7 @@ void destroy_session(struct session *s) struct session *new_session() { + int i; struct session *session = xmalloc(sizeof(*session)); yaz_log(YLOG_DEBUG, "New pazpar2 session"); @@ -1193,6 +1202,11 @@ struct session *new_session() session->query[0] = '\0'; session->nmem = nmem_create(); session->wrbuf = wrbuf_alloc(); + for (i = 0; i <= SESSION_WATCH_MAX; i++) + { + session->watchlist[i].data = 0; + session->watchlist[i].fun = 0; + } select_targets(session); diff --git a/pazpar2.h b/pazpar2.h index a14d691..8de4b91 100644 --- a/pazpar2.h +++ b/pazpar2.h @@ -89,6 +89,11 @@ struct client { struct client *next; }; +#define SESSION_WATCH_RECORDS 0 +#define SESSION_WATCH_MAX 0 + +typedef void (*session_watchfun)(void *data); + // End-user session struct session { struct client *clients; @@ -99,6 +104,10 @@ struct session { struct termlist *termlist; struct relevance *relevance; struct reclist *reclist; + struct { + void *data; + session_watchfun fun; + } watchlist[SESSION_WATCH_MAX + 1]; int total_hits; int total_records; }; @@ -150,6 +159,7 @@ void statistics(struct session *s, struct statistics *stat); char *search(struct session *s, char *query); struct record **show(struct session *s, int start, int *num, int *total, int *sumhits); struct termlist_score **termlist(struct session *s, int *num); +void session_set_watch(struct session *s, int what, session_watchfun fun, void *data); #endif -- 1.7.10.4