* 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 <yaz-z-assoc.h>
Yaz_Z_Query *m_last_query;
int m_last_resultCount;
int m_sr_transform;
+ int m_seqno;
};
/// Information Retrieval Proxy Server.
Yaz_ProxyClient *m_clientPool;
Yaz_Proxy *m_parent;
int m_seqno;
+ int m_max_clients;
int m_keepalive;
char *m_proxyTarget;
public:
void connectNotify();
void set_proxyTarget(const char *target);
char *get_proxyTarget() { return m_proxyTarget; };
+ void set_max_clients(int m) { m_max_clients = m; };
};
/*
- * 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.
*
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);
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");
}
* 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.
*
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);
}
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)
{
case 'v':
log_init_level (log_mask_str(arg));
break;
+ case 'c':
+ proxy->set_max_clients(atoi(arg));
+ break;
default:
usage(prog);
return 1;
* 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.
*
m_seqno = 1;
m_keepalive = 1;
m_proxyTarget = 0;
+ m_max_clients = 20;
}
Yaz_Proxy::~Yaz_Proxy()
{
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;
}
if (!strcmp(cookie,c->m_cookie))
{
logf (LOG_LOG, "Yaz_Proxy::get_client found cached target");
+ c->m_seqno = parent->m_seqno;
return c;
}
}
}
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;
}
void Yaz_ProxyClient::failNotify()
{
- logf (LOG_LOG, "connection closed by server");
+ logf (LOG_LOG, "connection closed by target");
shutdown();
}
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
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
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
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