Timeout per-service, obsoletes -T
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 23 Sep 2009 10:17:11 +0000 (12:17 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 23 Sep 2009 10:17:11 +0000 (12:17 +0200)
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.

12 files changed:
NEWS
doc/pazpar2.xml
doc/pazpar2_conf.xml
src/client.h
src/connection.c
src/connection.h
src/http_command.c
src/logic.c
src/parameters.h
src/pazpar2.c
src/pazpar2_config.c
src/pazpar2_config.h

diff --git a/NEWS b/NEWS
index 7e42df1..4ec5f16 100644 (file)
--- 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.
index c9b2614..92e0eb3 100644 (file)
@@ -33,7 +33,6 @@
    <arg choice="opt"><option>-l <replaceable>logfile</replaceable></option></arg>
    <arg choice="opt"><option>-p <replaceable>pidfile</replaceable></option></arg>
    <arg choice="opt"><option>-t</option></arg>
-   <arg choice="opt"><option>-T <replaceable>session_timeout</replaceable></option></arg>
    <arg choice="opt"><option>-u <replaceable>uid</replaceable></option></arg>
    <arg choice="opt"><option>-V</option></arg>
    <arg choice="opt"><option>-X</option></arg>
    </varlistentry>
 
    <varlistentry>
-    <term><option>-T <replaceable>session_timeout</replaceable></option></term>
-    <listitem>
-     <para>
-      Specifies a Pazpar2 HTTP session timeout. This
-      overrides the default value of 60 seconds which is to low for some broken browser.
-     </para>
-    </listitem>
-   </varlistentry>
-
-   <varlistentry>
     <term><option>-u <replaceable>uid</replaceable></option></term>
     <listitem>
      <para>
index c2d2227..9d08cbc 100644 (file)
        </listitem>
        </varlistentry>
 
+       <varlistentry>
+       <term>timeout</term>
+       <listitem>
+        <para>
+         Specifies timeout parameters for this service.
+         The <literal>timeout</literal>
+         element supports the following attributes: 
+         <literal>session</literal>, <literal>z3950_connect</literal>,
+         <literal>z3950_session</literal> which specifies
+         'session timeout', 'Z39.50 connect timeout', 'Z39.50 session timeout'
+         respectively.
+        </para>
+       </listitem>
+       </varlistentry>
+
       </variablelist>     <!-- Data elements in service directive -->
      </listitem>
     </varlistentry>
              </icu_chain>
            </relevance>
            <settings src="mysettings"/>
+           <timeout session="60"/>
         <service>
      </server>
    </pazpar2>
index 5772481..babaca5 100644 (file)
@@ -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);
index 8d8d48f..979f739 100644 (file)
@@ -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);
         }
     }
 
index 73c1a79..1580c7b 100644 (file)
@@ -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);
index 4b95b89..32c1dcb 100644 (file)
@@ -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;
index e927782..3da6ca3 100644 (file)
@@ -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);
         }
     }
index 3556626..412ed0d 100644 (file)
@@ -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;
 
index 5070a10..34bbf42 100644 (file)
@@ -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"
index ccc7722..dfb4509 100644 (file)
@@ -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"))
         {
index 64f80e6..6c4b33e 100644 (file)
@@ -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;