X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=pazpar2.c;h=1c43633d7bc2f9e3a13a114f31f8a2eb0d48702c;hb=eca54f46680e3da32c28be81f127be97049b6edb;hp=f953a7dc6b604f65da96c38adc1f7868e3ea8131;hpb=ecfbf76a7a6c560d2e7dcd107450ff58a7d316e5;p=pazpar2-moved-to-github.git diff --git a/pazpar2.c b/pazpar2.c index f953a7d..1c43633 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.14 2006-12-17 13:42:47 quinn Exp $ */; #include #include @@ -33,8 +33,9 @@ static void client_fatal(struct client *cl); static void connection_destroy(struct connection *co); static int client_prep_connection(struct client *cl); static void ingest_records(struct client *cl, Z_Records *r); +void session_alert_watch(struct session *s, int what); -IOCHAN channel_list = 0; // Master list of connections we're listening to. +IOCHAN channel_list = 0; // Master list of connections we're handling events to static struct connection *connection_freelist = 0; static struct client *client_freelist = 0; @@ -638,6 +639,7 @@ static struct record *ingest_record(struct client *cl, char *buf, int len) static void ingest_records(struct client *cl, Z_Records *r) { struct record *rec; + struct session *s = cl->session; Z_NamePlusRecordList *rlist; int i; @@ -669,6 +671,8 @@ static void ingest_records(struct client *cl, Z_Records *r) if (!rec) continue; } + if (s->watchlist[SESSION_WATCH_RECORDS].fun && rlist->num_records) + session_alert_watch(s, SESSION_WATCH_RECORDS); } static void do_presentResponse(IOCHAN i, Z_APDU *a) @@ -736,12 +740,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 +1119,21 @@ 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; +} + +void session_alert_watch(struct session *s, int what) +{ + if (!s->watchlist[what].fun) + return; + (*s->watchlist[what].fun)(s->watchlist[what].data); + s->watchlist[what].fun = 0; + s->watchlist[what].data = 0; +} + // 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 +1201,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 +1215,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);