Calculation of keepAlive timeout
authorGiannis Kosmas <kosmasgiannis@gmail.com>
Tue, 29 May 2012 00:32:28 +0000 (03:32 +0300)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 31 May 2012 13:43:49 +0000 (15:43 +0200)
keepAlive timeout is calculated based on session timeout defined in service configuration and is returned in the init response.

js/pz2.js
src/http_command.c

index a57688f..b321e5a 100644 (file)
--- a/js/pz2.js
+++ b/js/pz2.js
@@ -201,6 +201,9 @@ pz2.prototype =
                         context.sessionID = 
                             data.getElementsByTagName("session")[0]
                                 .childNodes[0].nodeValue;
+                        if (data.getElementsByTagName("keepAlive").length > 0) {
+                            context.keepAlive = data.getElementsByTagName("keepAlive")[0].childNodes[0].nodeValue;
+                        }
                         context.pingTimer =
                             setTimeout(
                                 function () {
index 567189e..84fac12 100644 (file)
@@ -470,6 +470,8 @@ static void cmd_init(struct http_channel *c)
     wrbuf_puts(c->wrbuf, "</session>"
                "<protocol>" PAZPAR2_PROTOCOL_VERSION "</protocol>");
     
+    wrbuf_printf(c->wrbuf, "<keepAlive>%d</keepAlive>\n", 1000 * ((s->psession->service->session_timeout >= 20) ?
+                                                                  (s->psession->service->session_timeout - 10) : 50));
     response_close(c, "init");
 }