From f7247294488509fca6dc8e0d32f63cd8ae51b555 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 23 Sep 2009 12:17:11 +0200 Subject: [PATCH] Timeout per-service, obsoletes -T Timeout values may be given per-service. That's element 'timeout' which takes three attribute values (a subset may be given): 'session', 'z3950_connect', 'z3950_session'. Option -T is no longer supported - used to specify session timeout. --- NEWS | 5 +++++ doc/pazpar2.xml | 11 ----------- doc/pazpar2_conf.xml | 16 ++++++++++++++++ src/client.h | 3 ++- src/connection.c | 19 ++++++++++++++----- src/connection.h | 1 - src/http_command.c | 2 +- src/logic.c | 6 ++---- src/parameters.h | 3 --- src/pazpar2.c | 14 +------------- src/pazpar2_config.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/pazpar2_config.h | 5 ++++- 12 files changed, 85 insertions(+), 41 deletions(-) diff --git a/NEWS b/NEWS index 7e42df1..4ec5f16 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +Timeout values may be given per-service. That's element 'timeout' +which takes three attribute values (a subset may be given): 'session', +'z3950_connect', 'z3950_session'. Option -T is no longer supported +- used to specify session timeout. + Option -t tests the Pazpar2 configuration and returns exit code (0=success, non-zero=failure). In previous version of Pazpar2, -t specified local settings. diff --git a/doc/pazpar2.xml b/doc/pazpar2.xml index c9b2614..92e0eb3 100644 --- a/doc/pazpar2.xml +++ b/doc/pazpar2.xml @@ -33,7 +33,6 @@ - @@ -130,16 +129,6 @@ - - - - Specifies a Pazpar2 HTTP session timeout. This - overrides the default value of 60 seconds which is to low for some broken browser. - - - - - diff --git a/doc/pazpar2_conf.xml b/doc/pazpar2_conf.xml index c2d2227..9d08cbc 100644 --- a/doc/pazpar2_conf.xml +++ b/doc/pazpar2_conf.xml @@ -393,6 +393,21 @@ + + timeout + + + Specifies timeout parameters for this service. + The timeout + element supports the following attributes: + session, z3950_connect, + z3950_session which specifies + 'session timeout', 'Z39.50 connect timeout', 'Z39.50 session timeout' + respectively. + + + + @@ -429,6 +444,7 @@ + diff --git a/src/client.h b/src/client.h index 5772481..babaca5 100644 --- a/src/client.h +++ b/src/client.h @@ -71,7 +71,8 @@ void client_destroy(struct client *c); void client_set_connection(struct client *cl, struct connection *con); void client_disconnect(struct client *cl); -int client_prep_connection(struct client *cl); +int client_prep_connection(struct client *cl, + int connect_timeout, int session_timeout); void client_start_search(struct client *cl); void client_set_session(struct client *cl, struct session *se); int client_is_active(struct client *cl); diff --git a/src/connection.c b/src/connection.c index 8d8d48f..979f739 100644 --- a/src/connection.c +++ b/src/connection.c @@ -65,6 +65,8 @@ struct connection { Conn_Connecting, Conn_Open } state; + int connect_timeout; + int session_timeout; struct connection *next; // next for same host or next in free list }; @@ -133,7 +135,9 @@ void connection_destroy(struct connection *co) // Creates a new connection for client, associated with the host of // client's database -static struct connection *connection_create(struct client *cl) +static struct connection *connection_create(struct client *cl, + int connect_timeout, + int session_timeout) { struct connection *new; struct host *host = client_get_host(cl); @@ -154,6 +158,8 @@ static struct connection *connection_create(struct client *cl) client_set_connection(cl, new); new->link = 0; new->state = Conn_Resolving; + new->connect_timeout = connect_timeout; + new->session_timeout = session_timeout; if (host->ipport) connection_connect(new); return new; @@ -201,7 +207,7 @@ static void non_block_events(struct connection *co) case ZOOM_EVENT_CONNECT: yaz_log(YLOG_LOG, "Connected to %s", client_get_url(cl)); co->state = Conn_Open; - iochan_settimeout(iochan, global_parameters.z3950_session_timeout); + iochan_settimeout(iochan, co->session_timeout); break; case ZOOM_EVENT_RECV_SEARCH: client_search_response(cl); @@ -385,7 +391,7 @@ static int connection_connect(struct connection *con) con->link = link; con->iochan = iochan_create(0, connection_handler, 0); con->state = Conn_Connecting; - iochan_settimeout(con->iochan, global_parameters.z3950_connect_timeout); + iochan_settimeout(con->iochan, con->connect_timeout); iochan_setdata(con->iochan, con); iochan_setsocketfun(con->iochan, socketfun); iochan_setmaskfun(con->iochan, maskfun); @@ -405,7 +411,8 @@ const char *connection_get_url(struct connection *co) } // Ensure that client has a connection associated -int client_prep_connection(struct client *cl) +int client_prep_connection(struct client *cl, + int connect_timeout, int session_timeout) { struct connection *co; struct session *se = client_get_session(cl); @@ -443,11 +450,13 @@ int client_prep_connection(struct client *cl) co->client = cl; /* tells ZOOM to reconnect if necessary. Disabled becuase the ZOOM_connection_connect flushes the task queue */ + co->connect_timeout = connect_timeout; + co->session_timeout = session_timeout; ZOOM_connection_connect(co->link, 0, 0); } else { - co = connection_create(cl); + co = connection_create(cl, connect_timeout, session_timeout); } } diff --git a/src/connection.h b/src/connection.h index 73c1a79..1580c7b 100644 --- a/src/connection.h +++ b/src/connection.h @@ -35,7 +35,6 @@ struct session; void connection_destroy(struct connection *co); void connect_resolver_host(struct host *host); -int connection_prep_connection(struct connection *co, struct session *se); const char *connection_get_url(struct connection *co); void connection_release(struct connection *co); ZOOM_connection connection_get_link(struct connection *co); diff --git a/src/http_command.c b/src/http_command.c index 4b95b89..32c1dcb 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -75,7 +75,7 @@ struct http_session *http_session_create(struct conf_service *service) session_list = r; r->timeout_iochan = iochan_create(-1, session_timeout, 0); iochan_setdata(r->timeout_iochan, r); - iochan_settimeout(r->timeout_iochan, global_parameters.session_timeout); + iochan_settimeout(r->timeout_iochan, service->session_timeout); pazpar2_add_channel(r->timeout_iochan); return r; diff --git a/src/logic.c b/src/logic.c index e927782..3da6ca3 100644 --- a/src/logic.c +++ b/src/logic.c @@ -79,10 +79,7 @@ struct parameters global_parameters = { 0, // dump_records 0, // debug_mode - 60, // session timeout 100, - 180, // Z39.50 session timeout - 15 // Connect timeout }; static void log_xml_doc(xmlDoc *doc) @@ -569,7 +566,8 @@ enum pazpar2_error_code search(struct session *se, else { no_working++; - if (client_prep_connection(cl)) + if (client_prep_connection(cl, se->service->z3950_connect_timeout, + se->service->z3950_session_timeout)) client_start_search(cl); } } diff --git a/src/parameters.h b/src/parameters.h index 3556626..412ed0d 100644 --- a/src/parameters.h +++ b/src/parameters.h @@ -26,10 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA struct parameters { int dump_records; int debug_mode; - int session_timeout; int toget; - int z3950_session_timeout; - int z3950_connect_timeout; }; extern struct parameters global_parameters; diff --git a/src/pazpar2.c b/src/pazpar2.c index 5070a10..34bbf42 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -90,7 +90,6 @@ static int sc_main( char *arg; const char *pidfile = 0; const char *uid = 0; - int session_timeout = 60; const char *listener_override = 0; const char *config_fname = 0; struct conf_config *config = 0; @@ -106,7 +105,7 @@ static int sc_main( yaz_log_init_prefix("pazpar2"); yaz_log_xml_errors(0, YLOG_WARN); - while ((ret = options("dDf:h:l:p:tT:u:VX", argv, argc, &arg)) != -2) + while ((ret = options("dDf:h:l:p:tu:VX", argv, argc, &arg)) != -2) { switch (ret) { @@ -132,16 +131,6 @@ static int sc_main( case 't': test_mode = 1; break; - case 'T': - session_timeout = atoi(arg); - if (session_timeout < 9 || session_timeout > 86400) - { - yaz_log(YLOG_FATAL, "Session timeout out of range 10..86400: %d", - session_timeout); - return 1; - } - global_parameters.session_timeout = session_timeout; - break; case 'u': uid = arg; break; @@ -159,7 +148,6 @@ static int sc_main( " -l file Log to file\n" " -p pidfile PID file\n" " -t Test configuration\n" - " -T session_timeout Session timeout\n" " -u uid Change user to uid\n" " -V Show version\n" " -X Debug mode\n" diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index ccc7722..dfb4509 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -128,6 +128,9 @@ static struct conf_service *service_init(struct conf_config *config, service->databases = 0; service->targetprofiles = 0; service->config = config; + service->session_timeout = 60; /* default session timeout */ + service->z3950_session_timeout = 180; + service->z3950_connect_timeout = 15; service->relevance_pct = 0; service->sort_pct = 0; @@ -454,7 +457,43 @@ static struct conf_service *service_create(struct conf_config *config, { if (n->type != XML_ELEMENT_NODE) continue; - if (!strcmp((const char *) n->name, "settings")) + if (!strcmp((const char *) n->name, "timeout")) + { + xmlChar *src = xmlGetProp(n, (xmlChar *) "session"); + if (src) + { + service->session_timeout = atoi((const char *) src); + xmlFree(src); + if (service->session_timeout < 9) + { + yaz_log(YLOG_FATAL, "session timeout out of range"); + return 0; + } + } + src = xmlGetProp(n, (xmlChar *) "z3950_connect"); + if (src) + { + service->z3950_connect_timeout = atoi((const char *) src); + xmlFree(src); + if (service->z3950_session_timeout < 9) + { + yaz_log(YLOG_FATAL, "Z39.50 connect timeout out of range"); + return 0; + } + } + src = xmlGetProp(n, (xmlChar *) "z3950_session"); + if (src) + { + service->z3950_session_timeout = atoi((const char *) src); + xmlFree(src); + if (service->z3950_session_timeout < 9) + { + yaz_log(YLOG_FATAL, "Z39.50 session timeout out of range"); + return 0; + } + } + } + else if (!strcmp((const char *) n->name, "settings")) got_settings++; else if (!strcmp((const char *) n->name, (const char *) "targetprofiles")) { diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h index 64f80e6..6c4b33e 100644 --- a/src/pazpar2_config.h +++ b/src/pazpar2_config.h @@ -105,7 +105,10 @@ struct conf_service char *id; char *settings; NMEM nmem; - + int session_timeout; + int z3950_session_timeout; + int z3950_connect_timeout; + /* duplicated from conf_server */ pp2_charset_t relevance_pct; pp2_charset_t sort_pct; -- 1.7.10.4