From: Adam Dickmeiss Date: Tue, 4 Jul 2000 13:48:49 +0000 (+0000) Subject: Implemented upper-limit on proxy-to-target sessions. X-Git-Tag: YAZPP.0.3~89 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=acd0ff2a7f87fb33a82475dcc7aa44cd7189d4c0;p=yazpp-moved-to-github.git Implemented upper-limit on proxy-to-target sessions. --- diff --git a/include/yaz-proxy.h b/include/yaz-proxy.h index cdd8cc3..8fbbb71 100644 --- a/include/yaz-proxy.h +++ b/include/yaz-proxy.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: yaz-proxy.h,v 1.9 1999-12-06 13:52:45 adam Exp $ + * $Id: yaz-proxy.h,v 1.10 2000-07-04 13:48:49 adam Exp $ */ #include @@ -30,6 +30,7 @@ class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc { Yaz_Z_Query *m_last_query; int m_last_resultCount; int m_sr_transform; + int m_seqno; }; /// Information Retrieval Proxy Server. @@ -46,6 +47,7 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { Yaz_ProxyClient *m_clientPool; Yaz_Proxy *m_parent; int m_seqno; + int m_max_clients; int m_keepalive; char *m_proxyTarget; public: @@ -58,5 +60,6 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { void connectNotify(); void set_proxyTarget(const char *target); char *get_proxyTarget() { return m_proxyTarget; }; + void set_max_clients(int m) { m_max_clients = m; }; }; diff --git a/src/yaz-client.cpp b/src/yaz-client.cpp index 2bd47b1..a6558dc 100644 --- a/src/yaz-client.cpp +++ b/src/yaz-client.cpp @@ -1,10 +1,13 @@ /* - * Copyright (c) 1998-1999, Index Data. + * Copyright (c) 1998-2000, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-client.cpp,v $ - * Revision 1.10 2000-05-30 03:12:27 ian + * Revision 1.11 2000-07-04 13:48:49 adam + * Implemented upper-limit on proxy-to-target sessions. + * + * Revision 1.10 2000/05/30 03:12:27 ian * minor change to stop g++ 2.95.2 complaining about taking the address * of a member function. * @@ -86,6 +89,7 @@ public: void connectNotify(); void failNotify(); void timeoutNotify(); + char *get_cookie (Z_OtherInformation **oi); int processCommand(const char *cmd); const char *MyClient::getCommand(); int cmd_open(char *host); @@ -137,15 +141,40 @@ MyClient::MyClient(IYaz_PDU_Observable *the_PDU_Observable, void usage(char *prog) { - fprintf (stderr, "%s: [-v log] [-p proxy] [zurl]\n", prog); + fprintf (stderr, "%s: [-v log] [-c cookie] [-p proxy] [zurl]\n", prog); exit (1); } +char *MyClient::get_cookie(Z_OtherInformation **otherInfo) +{ + int oid[OID_SIZE]; + Z_OtherInformationUnit *oi; + struct oident ent; + ent.proto = PROTO_Z3950; + ent.oclass = CLASS_USERINFO; + ent.value = (oid_value) VAL_COOKIE; + + if (oid_ent_to_oid (&ent, oid) && + (oi = update_otherInformation(otherInfo, 0, oid, 1, 1)) && + oi->which == Z_OtherInfo_characterInfo) + return oi->information.characterInfo; + return 0; +} + void MyClient::recv_initResponse(Z_InitResponse *initResponse) { printf ("Got InitResponse. Status "); if (*initResponse->result) + { printf ("Ok\n"); + + const char *p = get_cookie (&initResponse->otherInfo); + if (p) + { + printf ("cookie = %s\n", p); + set_cookie(p); + } + } else printf ("Fail\n"); } diff --git a/src/yaz-proxy-main.cpp b/src/yaz-proxy-main.cpp index 126b5bb..17d3eb1 100644 --- a/src/yaz-proxy-main.cpp +++ b/src/yaz-proxy-main.cpp @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-proxy-main.cpp,v $ - * Revision 1.7 1999-12-06 13:52:45 adam + * Revision 1.8 2000-07-04 13:48:49 adam + * Implemented upper-limit on proxy-to-target sessions. + * + * Revision 1.7 1999/12/06 13:52:45 adam * Modified for new location of YAZ header files. Experimental threaded * operation. * @@ -39,7 +42,7 @@ void usage(char *prog) { - fprintf (stderr, "%s: [-v log] [-t target] @:port\n", prog); + fprintf (stderr, "%s: [-c num] [-v log] [-t target] @:port\n", prog); exit (1); } @@ -51,7 +54,7 @@ int args(Yaz_Proxy *proxy, int argc, char **argv) char *prog = argv[0]; int ret; - while ((ret = options("t:v:", argv, argc, &arg)) != -2) + while ((ret = options("t:v:c:", argv, argc, &arg)) != -2) { switch (ret) { @@ -69,6 +72,9 @@ int args(Yaz_Proxy *proxy, int argc, char **argv) case 'v': log_init_level (log_mask_str(arg)); break; + case 'c': + proxy->set_max_clients(atoi(arg)); + break; default: usage(prog); return 1; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index b985cd1..7cdbe93 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-proxy.cpp,v $ - * Revision 1.11 1999-12-06 13:52:45 adam + * Revision 1.12 2000-07-04 13:48:49 adam + * Implemented upper-limit on proxy-to-target sessions. + * + * Revision 1.11 1999/12/06 13:52:45 adam * Modified for new location of YAZ header files. Experimental threaded * operation. * @@ -59,6 +62,7 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable) : m_seqno = 1; m_keepalive = 1; m_proxyTarget = 0; + m_max_clients = 20; } Yaz_Proxy::~Yaz_Proxy() @@ -80,7 +84,7 @@ IYaz_PDU_Observer *Yaz_Proxy::clone(IYaz_PDU_Observable { Yaz_Proxy *new_proxy = new Yaz_Proxy(the_PDU_Observable); new_proxy->m_parent = this; - new_proxy->timeout(20); + new_proxy->timeout(120); new_proxy->set_proxyTarget(m_proxyTarget); return new_proxy; } @@ -137,6 +141,7 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) if (!strcmp(cookie,c->m_cookie)) { logf (LOG_LOG, "Yaz_Proxy::get_client found cached target"); + c->m_seqno = parent->m_seqno; return c; } } @@ -161,19 +166,53 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) } if (!m_proxyTarget) return 0; - logf (LOG_LOG, "Yaz_Proxy::get_client creating new"); - c = new Yaz_ProxyClient(m_PDU_Observable->clone()); - c->m_next = parent->m_clientPool; - if (c->m_next) - c->m_next->m_prev = &c->m_next; - parent->m_clientPool = c; - c->m_prev = &parent->m_clientPool; + Yaz_ProxyClient *c_min = 0; + int min_seq = -1; + int no_of_clients = 0; + for (c = parent->m_clientPool; c; c = c->m_next) + { + no_of_clients++; + logf (LOG_LOG, "found seqno = %d", c->m_seqno); + if (min_seq < 0 || c->m_seqno < min_seq) + { + min_seq = c->m_seqno; + c_min = c; + } + } + if (no_of_clients >= parent->m_max_clients) + { + c = c_min; + logf (LOG_LOG, "Yaz_Proxy::get_client re-using session %d", + c->m_seqno); + if (c->m_server) + delete c->m_server; + c->m_server = 0; + } + else + { + logf (LOG_LOG, "Yaz_Proxy::get_client making new session"); + c = new Yaz_ProxyClient(m_PDU_Observable->clone()); + c->m_next = parent->m_clientPool; + if (c->m_next) + c->m_next->m_prev = &c->m_next; + parent->m_clientPool = c; + c->m_prev = &parent->m_clientPool; + } sprintf (c->m_cookie, "%d", parent->m_seqno); - (parent->m_seqno)++; - + logf (LOG_LOG, "Yaz_Proxy::get_client new session %s", c->m_cookie); + c->m_seqno = parent->m_seqno; c->client(m_proxyTarget); + c->m_init_flag = 0; + + delete c->m_last_query; + c->m_last_query = 0; + c->m_last_resultCount = 0; + c->m_sr_transform = 0; + c->timeout(600); + + (parent->m_seqno)++; } return c; } @@ -329,7 +368,7 @@ void Yaz_Proxy::failNotify() void Yaz_ProxyClient::failNotify() { - logf (LOG_LOG, "connection closed by server"); + logf (LOG_LOG, "connection closed by target"); shutdown(); } diff --git a/unix/configure b/unix/configure index af8736b..7a75634 100755 --- a/unix/configure +++ b/unix/configure @@ -12,7 +12,7 @@ ac_help= ac_default_prefix=/usr/local # Any additions from configure.in: ac_help="$ac_help - --with-yazconfig Path for yaz-config" + --with-yazconfig=DIR yaz-config in DIR (example /home/yaz-1.6)" # Initialize some variables set by options. # The variables have the same names as the options, with @@ -1139,7 +1139,7 @@ if test "x$yazpath" != "xNONE"; then else for i in ../../yaz* ../../yaz; do if test -d $i; then - if test -r $i/include/yaz/yaz-version.h; then + if test -r $i/yaz-config; then yazconfig=$i/yaz-config fi fi diff --git a/unix/configure.in b/unix/configure.in index 87fb89e..6398e2c 100644 --- a/unix/configure.in +++ b/unix/configure.in @@ -1,7 +1,7 @@ dnl YAZ++ Toolkit configure script. dnl (c) Index Data ApS 1999 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.3 1999-12-06 13:52:45 adam Exp $ +dnl $Id: configure.in,v 1.4 2000-07-04 13:48:49 adam Exp $ AC_INIT(../include/yaz-socket-manager.h) dnl dnl ------ Checking programs @@ -20,13 +20,13 @@ AC_SUBST(YAZINC) AC_SUBST(YAZLIB) yazconfig=NONE yazpath=NONE -AC_ARG_WITH(yazconfig, [ --with-yazconfig Path for yaz-config], [yazpath=$withval]) +AC_ARG_WITH(yazconfig, [ --with-yazconfig=DIR yaz-config in DIR (example /home/yaz-1.6)], [yazpath=$withval]) if test "x$yazpath" != "xNONE"; then yazconfig=$yazpath/yaz-config else for i in ../../yaz* ../../yaz; do if test -d $i; then - if test -r $i/include/yaz/yaz-version.h; then + if test -r $i/yaz-config; then yazconfig=$i/yaz-config fi fi