The per-target setting 'max-sockets' allows number of sockets to be in
use. If reached and HTTP is in use a HTTP response with status code 500
is returned.
<para>
The proxy config file must have a root element called
<literal>proxy</literal> and scoped within namespace
<para>
The proxy config file must have a root element called
<literal>proxy</literal> and scoped within namespace
- <literal> xmlns="http://indexdata.dk/yazproxy/schema/0.9/</literal>.
+ <literal> xmlns="http://indexdata.dk/yazproxy/schema/0.9/"</literal>.
All information except an optional XML header must be stored
within the <literal>proxy</literal> element.
</para>
All information except an optional XML header must be stored
within the <literal>proxy</literal> element.
</para>
equivalent to command line option <literal>-t</literal>.
</para>
<para>
equivalent to command line option <literal>-t</literal>.
</para>
<para>
- <screen>
- <?xml version="1.0"?>
- <proxy xmlns="http://indexdata.dk/yazproxy/schema/0.9/">
- <target name="server1" default="1">
- <!-- description of server1 .. -->
- </target>
- <target name="server2">
- <!-- description of server2 .. -->
- </target>
- </proxy>
+ <screen><![CDATA[
+ <?xml version="1.0"?>
+ <proxy xmlns="http://indexdata.dk/yazproxy/schema/0.9/">
+ <target name="server1" default="1">
+ <!-- description of server1 .. -->
+ </target>
+ <target name="server2">
+ <!-- description of server2 .. -->
+ </target>
+ </proxy>
+ ]]>
</screen>
</para>
</section>
</screen>
</para>
</section>
+ <section id="proxy-config-max-sockets">
+ <title>client-timeout</title>
+ <para>
+ The element <literal>max-sockets</literal> is the child of element
+ <literal>target</literal> and specifies the maximum number of sockets
+ to use for the target for all sessions using it. In other words: maximum
+ number of Z39.50 session to the target.
+ </para>
+ </section>
+
<section id="proxy-config-keepalive">
<title>keepalive</title>
<para>The <literal>keepalive</literal> element holds information about
<section id="proxy-config-keepalive">
<title>keepalive</title>
<para>The <literal>keepalive</literal> element holds information about
<xs:element ref="url" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="target-timeout" minOccurs="0"/>
<xs:element ref="client-timeout" minOccurs="0"/>
<xs:element ref="url" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="target-timeout" minOccurs="0"/>
<xs:element ref="client-timeout" minOccurs="0"/>
+ <xs:element ref="max-sockets" minOccurs="0"/>
<xs:element ref="keepalive" minOccurs="0"/>
<xs:element ref="limit" minOccurs="0"/>
<xs:element ref="attribute" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="keepalive" minOccurs="0"/>
<xs:element ref="limit" minOccurs="0"/>
<xs:element ref="attribute" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="url" type="xs:string"/>
<xs:element name="target-timeout" type="xs:integer"/>
<xs:element name="client-timeout" type="xs:integer"/>
<xs:element name="url" type="xs:string"/>
<xs:element name="target-timeout" type="xs:integer"/>
<xs:element name="client-timeout" type="xs:integer"/>
+ <xs:element name="max-sockets" type="xs:integer"/>
<xs:element name="bandwidth" type="xs:integer"/>
<xs:element name="pdu" type="xs:integer"/>
<xs:element name="retrieve" type="xs:integer"/>
<xs:element name="bandwidth" type="xs:integer"/>
<xs:element name="pdu" type="xs:integer"/>
<xs:element name="retrieve" type="xs:integer"/>
<url>localhost:9999</url>
<target-timeout>60</target-timeout>
<client-timeout>20</client-timeout>
<url>localhost:9999</url>
<target-timeout>60</target-timeout>
<client-timeout>20</client-timeout>
+ <max-sockets>8</max-sockets>
<!-- <target-authentication type="open">a/b</target-authentication> -->
<keepalive>
<bandwidth>100000</bandwidth>
<!-- <target-authentication type="open">a/b</target-authentication> -->
<keepalive>
<bandwidth>100000</bandwidth>
</syntax>
<syntax type="*" error="238"/>
</syntax>
<syntax type="*" error="238"/>
<xi:include href="explain.xml"/>
<target-charset>iso-8859-1</target-charset>
<cql2rpn>pqf.properties</cql2rpn>
<xi:include href="explain.xml"/>
<target-charset>iso-8859-1</target-charset>
<cql2rpn>pqf.properties</cql2rpn>
void HTTP_Forwarded(Z_GDU *z_gdu);
void connect_stat(bool &block, int &reduce);
Yaz_ProxyClient *get_client(Z_APDU *apdu, const char *cookie,
void HTTP_Forwarded(Z_GDU *z_gdu);
void connect_stat(bool &block, int &reduce);
Yaz_ProxyClient *get_client(Z_APDU *apdu, const char *cookie,
- const char *proxy_host);
+ const char *proxy_host, int *http_code);
void srw_get_client(const char *db, const char **backend_db);
void srw_get_client(const char *db, const char **backend_db);
+ int get_number_of_connections();
Z_APDU *result_set_optimize(Z_APDU *apdu);
void releaseClient();
Yaz_ProxyClient *m_client;
Z_APDU *result_set_optimize(Z_APDU *apdu);
void releaseClient();
Yaz_ProxyClient *m_client;
int m_keepalive_limit_pdu;
int m_client_idletime;
int m_target_idletime;
int m_keepalive_limit_pdu;
int m_client_idletime;
int m_target_idletime;
int m_debug_mode;
char *m_proxyTarget;
char *m_default_target;
int m_debug_mode;
char *m_proxyTarget;
char *m_default_target;
int *limit_bw, int *limit_pdu, int *limit_req,
int *limit_search,
int *target_idletime, int *client_idletime,
int *limit_bw, int *limit_pdu, int *limit_req,
int *limit_search,
int *target_idletime, int *client_idletime,
int *max_clients,
int *keepalive_limit_bw, int *keepalive_limit_pdu,
int *pre_init,
int *max_clients,
int *keepalive_limit_bw, int *keepalive_limit_pdu,
int *pre_init,
int *limit_bw, int *limit_pdu, int *limit_req,
int *limit_search,
int *target_idletime, int *client_idletime,
int *limit_bw, int *limit_pdu, int *limit_req,
int *limit_search,
int *target_idletime, int *client_idletime,
int *keepalive_limit_bw, int *keepalive_limit_pdu,
int *pre_init, const char **cql2rpn,
const char **negotiation_charset,
int *keepalive_limit_bw, int *keepalive_limit_pdu,
int *pre_init, const char **cql2rpn,
const char **negotiation_charset,
int *limit_search,
int *target_idletime,
int *client_idletime,
int *limit_search,
int *target_idletime,
int *client_idletime,
int *keepalive_limit_bw,
int *keepalive_limit_pdu,
int *pre_init,
int *keepalive_limit_bw,
int *keepalive_limit_pdu,
int *pre_init,
}
}
if (ptr->type == XML_ELEMENT_NODE
}
}
if (ptr->type == XML_ELEMENT_NODE
+ && !strcmp((const char *) ptr->name, "max-sockets"))
+ {
+ const char *t = get_text(ptr);
+ if (t && max_sockets)
+ {
+ *max_sockets = atoi(t);
+ }
+ }
+ if (ptr->type == XML_ELEMENT_NODE
&& !strcmp((const char *) ptr->name, "cql2rpn"))
{
const char *t = get_text(ptr);
&& !strcmp((const char *) ptr->name, "cql2rpn"))
{
const char *t = get_text(ptr);
limit_bw, limit_pdu, limit_req,
limit_search,
target_idletime, client_idletime,
limit_bw, limit_pdu, limit_req,
limit_search,
target_idletime, client_idletime,
keepalive_limit_bw, keepalive_limit_pdu,
pre_init, cql2rpn,
negotiation_charset, negotiation_lang, target_charset,
keepalive_limit_bw, keepalive_limit_pdu,
pre_init, cql2rpn,
negotiation_charset, negotiation_lang, target_charset,
int *limit_search,
int *target_idletime,
int *client_idletime,
int *limit_search,
int *target_idletime,
int *client_idletime,
int *max_clients,
int *keepalive_limit_bw,
int *keepalive_limit_pdu,
int *max_clients,
int *keepalive_limit_bw,
int *keepalive_limit_pdu,
m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
limit_search,
target_idletime, client_idletime,
m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
limit_search,
target_idletime, client_idletime,
keepalive_limit_bw, keepalive_limit_pdu,
pre_init, cql2rpn,
negotiation_charset, negotiation_lang,
keepalive_limit_bw, keepalive_limit_pdu,
pre_init, cql2rpn,
negotiation_charset, negotiation_lang,
/* $Id: yaz-proxy.cpp,v 1.78 2008-02-21 09:33:23 adam Exp $
/* $Id: yaz-proxy.cpp,v 1.78 2008-02-21 09:33:23 adam Exp $
- Copyright (c) 1998-2007, Index Data.
+ Copyright (c) 1998-2008, Index Data.
This file is part of the yazproxy.
This file is part of the yazproxy.
m_seed = time(0);
m_client_idletime = 600;
m_target_idletime = 600;
m_seed = time(0);
m_client_idletime = 600;
m_target_idletime = 600;
m_optimize = xstrdup ("1");
strcpy(m_session_str, "0 ");
m_session_no = 0;
m_optimize = xstrdup ("1");
strcpy(m_session_str, "0 ");
m_session_no = 0;
+int Yaz_Proxy::get_number_of_connections()
+{
+ int no_connections = 0;
+ Yaz_ProxyClient *c;
+
+ for (c = m_parent->m_clientPool; c; c = c->m_next)
+ {
+ assert(c->m_prev);
+ assert(*c->m_prev == c);
+ if (!strcmp(m_proxyTarget, c->get_hostname()))
+ {
+ no_connections++;
+ }
+ }
+ yaz_log (YLOG_LOG, "%sExisting %s connections: %d", m_session_str, m_proxyTarget,
+ no_connections);
+ return no_connections;
+}
+
Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie,
Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie,
- const char *proxy_host)
+ const char *proxy_host, int *http_code)
{
assert (m_parent);
Yaz_Proxy *parent = m_parent;
{
assert (m_parent);
Yaz_Proxy *parent = m_parent;
&m_pdu_max, &m_max_record_retrieve,
&m_search_max,
&m_target_idletime, &client_idletime,
&m_pdu_max, &m_max_record_retrieve,
&m_search_max,
&m_target_idletime, &client_idletime,
&parent->m_max_clients,
&m_keepalive_limit_bw,
&m_keepalive_limit_pdu,
&parent->m_max_clients,
&m_keepalive_limit_bw,
&m_keepalive_limit_pdu,
{
assert(c->m_prev);
assert(*c->m_prev == c);
{
assert(c->m_prev);
assert(*c->m_prev == c);
- if (c->m_server == 0 && c->m_cookie == 0 && c->m_waiting == 0
+ if (c->m_server == 0 && c->m_cookie == 0 && c->m_waiting == 0
&& c->compare_idAuthentication(apdu)
&& c->compare_charset(apdu)
&& !strcmp(m_proxyTarget, c->get_hostname()))
&& c->compare_idAuthentication(apdu)
&& c->compare_charset(apdu)
&& !strcmp(m_proxyTarget, c->get_hostname()))
if (apdu->which != Z_APDU_initRequest)
{
yaz_log (YLOG_LOG, "%sno init request as first PDU", m_session_str);
if (apdu->which != Z_APDU_initRequest)
{
yaz_log (YLOG_LOG, "%sno init request as first PDU", m_session_str);
+ *http_code = 500;
+ return 0;
+ }
+
+ int no_in_use = get_number_of_connections();
+ if (no_in_use >= m_max_sockets)
+ {
+ yaz_log (YLOG_LOG, "%smax sockets reached %d", m_session_str,
+ m_max_sockets);
+ *http_code = 500;
return 0;
}
// go through list of clients - and find the lowest/oldest one.
return 0;
}
// go through list of clients - and find the lowest/oldest one.
yaz_log (YLOG_LOG, "%sNEW %d %s",
m_session_str, parent->m_seqno, m_proxyTarget);
c = new Yaz_ProxyClient(m_PDU_Observable->clone(), parent);
yaz_log (YLOG_LOG, "%sNEW %d %s",
m_session_str, parent->m_seqno, m_proxyTarget);
c = new Yaz_ProxyClient(m_PDU_Observable->clone(), parent);
else
{
// Use _client_ IP as shown in the log entries...!
else
{
// Use _client_ IP as shown in the log entries...!
- yaz_log(YLOG_LOG, "No authorization_str present: use client IP: %s\n", m_peername);
-
auth = (Z_IdAuthentication *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdAuthentication));
auth->which = Z_IdAuthentication_idPass;
auth->u.idPass = (Z_IdPass *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdPass));
auth = (Z_IdAuthentication *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdAuthentication));
auth->which = Z_IdAuthentication_idPass;
auth->u.idPass = (Z_IdPass *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdPass));
// Determine our client.
Z_OtherInformation **oi;
get_otherInfoAPDU(apdu, &oi);
// Determine our client.
Z_OtherInformation **oi;
get_otherInfoAPDU(apdu, &oi);
- m_client = get_client(apdu, get_cookie(oi), get_proxy(oi));
+ int http_code = 404;
+ m_client = get_client(apdu, get_cookie(oi), get_proxy(oi), &http_code);
if (!m_client)
{
if (m_http_version)
{ // HTTP. Send not found
if (!m_client)
{
if (m_http_version)
{ // HTTP. Send not found
- send_http_response(404);
+ send_http_response(http_code);