From 538b41355b5607b4bd09c9c98682694fd6628940 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 17 Jan 2007 13:22:53 +0000 Subject: [PATCH] Experiment with check for dead sessions. --- include/idzebra/api.h | 7 ++++++- index/index.h | 5 ++++- index/zebraapi.c | 15 ++++++++++++++- index/zebrasrv.c | 13 ++++++++++++- index/zsets.c | 11 ++++++++++- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/include/idzebra/api.h b/include/idzebra/api.h index 1a41b65..3b7268a 100644 --- a/include/idzebra/api.h +++ b/include/idzebra/api.h @@ -1,4 +1,4 @@ -/* $Id: api.h,v 1.43 2007-01-16 15:01:15 adam Exp $ +/* $Id: api.h,v 1.44 2007-01-17 13:22:53 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -497,6 +497,11 @@ struct BFiles_struct *zebra_get_bfs(ZebraHandle zh); YAZ_EXPORT ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids); +YAZ_EXPORT +ZEBRA_RES zebra_set_busy_handler(ZebraHandle zh, + int (*f)(void *client_data, ZebraHandle zh), + void *client_data); + YAZ_END_CDECL /** \mainpage Zebra diff --git a/index/index.h b/index/index.h index 92a4e22..7a66bad 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.192 2007-01-16 15:31:23 adam Exp $ +/* $Id: index.h,v 1.193 2007-01-17 13:22:53 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -233,6 +233,9 @@ struct zebra_session { NMEM nmem_error; struct zebra_limit *m_limit; + + int (*busy_handler_func)(void *client_data); + void *busy_handler_data; }; diff --git a/index/zebraapi.c b/index/zebraapi.c index 091fbf8..ccf5f3b 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.244 2007-01-16 15:31:23 adam Exp $ +/* $Id: zebraapi.c,v 1.245 2007-01-17 13:22:53 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -143,6 +143,9 @@ ZebraHandle zebra_open(ZebraService zs, Res res) zh->m_staticrank = 0; zh->m_segment_indexing = 0; + zh->busy_handler_func = 0; + zh->busy_handler_data = 0; + default_encoding = res_get_def(zh->session_res, "encoding", "ISO-8859-1"); zh->iconv_to_utf8 = @@ -1020,6 +1023,16 @@ void zebra_set_partial_result(ZebraHandle zh) zh->partial_result = 1; } + +ZEBRA_RES zebra_set_busy_handler(ZebraHandle zh, + int (*f)(void *client_data, ZebraHandle zh), + void *client_data) +{ + zh->busy_handler_func = f; + zh->busy_handler_data = client_data; + return ZEBRA_OK; +} + ZEBRA_RES zebra_search_RPN_x(ZebraHandle zh, ODR o, Z_RPNQuery *query, const char *setname, zint *hits, int *estimated_hit_count, diff --git a/index/zebrasrv.c b/index/zebrasrv.c index 234fae0..bbc354a 100644 --- a/index/zebrasrv.c +++ b/index/zebrasrv.c @@ -1,4 +1,4 @@ -/* $Id: zebrasrv.c,v 1.6 2007-01-16 15:01:15 adam Exp $ +/* $Id: zebrasrv.c,v 1.7 2007-01-17 13:22:53 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -261,6 +261,15 @@ static void search_terms(ZebraHandle zh, bend_search_rr *r) } } + +static int busy_handler(void *client_data, ZebraHandle zh) +{ + bend_association assoc =(bend_association) client_data; + if (!bend_assoc_is_alive(assoc)) + return 1; + return 0; +} + int bend_search(void *handle, bend_search_rr *r) { ZebraHandle zh = (ZebraHandle) handle; @@ -274,6 +283,7 @@ int bend_search(void *handle, bend_search_rr *r) zebra_result (zh, &r->errcode, &r->errstring); return 0; } + zebra_set_busy_handler(zh, busy_handler, r->association); yaz_log (YLOG_DEBUG, "ResultSet '%s'", r->setname); switch (r->query->which) { @@ -299,6 +309,7 @@ int bend_search(void *handle, bend_search_rr *r) default: r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP; } + zebra_set_busy_handler(zh, 0, 0); return 0; } diff --git a/index/zsets.c b/index/zsets.c index e424abe..74a4733 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.117 2007-01-16 15:31:23 adam Exp $ +/* $Id: zsets.c,v 1.118 2007-01-17 13:22:53 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -1028,6 +1028,15 @@ ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet, key_logdump_txt(log_level_searchhits, &key, termid->name); if (this_sys != psysno) { /* new record .. */ + if (zh->busy_handler_func) + { + if (zh->busy_handler_func(zh->busy_handler_data)) + { + yaz_log(YLOG_LOG, "Session end. Stop search"); + zebraSet->estimated_hit_count = 1; + break; + } + } if (rfd->counted_items > rset->hits_limit) { zebraSet->estimated_hit_count = 1; -- 1.7.10.4