/* This file is part of Metaproxy.
- Copyright (C) 2005-2012 Index Data
+ Copyright (C) Index Data
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
#include <yazpp/limit-connect.h>
#include <yaz/timing.h>
#include <yaz/log.h>
+#include <yaz/daemon.h>
#include "gduutil.hpp"
+#include <signal.h>
#include <iostream>
friend class FrontendNet;
std::string port;
std::string route;
+ std::string cert_fname;
+ int max_recv_bytes;
};
class FrontendNet::Rep {
friend class FrontendNet;
std::string m_stat_req;
yazpp_1::SocketManager mySocketManager;
ZAssocServer **az;
+ yazpp_1::PDU_Assoc **pdu;
int m_duration_freq[22];
double m_duration_lim[22];
double m_duration_max;
double m_duration_min;
double m_duration_total;
- bool m_stop;
+ int m_stop_signo;
public:
Rep();
~Rep();
const char *peername = PDU_Observable->getpeername();
if (!peername)
peername = "unknown";
+ else
+ {
+ const char *cp = strchr(peername, ':');
+ if (cp)
+ peername = cp + 1;
+ }
m_origin.set_tcpip_address(std::string(peername), m_session.id());
timeout(m_p->m_session_timeout);
}
}
void yf::FrontendNet::ZAssocServer::set_thread_pool(
- ThreadPoolSocketObserver *observer)
+ mp::ThreadPoolSocketObserver *observer)
{
m_thread_pool_observer = observer;
}
m_duration_max = 0.0;
m_duration_min = 0.0;
m_duration_total = 0.0;
- m_stop = false;
+ m_stop_signo = 0;
}
yf::FrontendNet::Rep::~Rep()
for (i = 0; i < m_ports.size(); i++)
delete az[i];
delete [] az;
+ delete [] pdu;
}
az = 0;
}
{
}
-void yf::FrontendNet::stop() const
+void yf::FrontendNet::stop(int signo) const
{
- m_p->m_stop = true;
+ m_p->m_stop_signo = signo;
}
bool yf::FrontendNet::My_Timer_Thread::timeout()
m_obs->deleteObserver(this);
}
-void yf::FrontendNet::process(Package &package) const
+void yf::FrontendNet::process(mp::Package &package) const
{
if (m_p->az == 0)
return;
}
while (m_p->mySocketManager.processEvent() > 0)
{
- if (m_p->m_stop)
+ if (m_p->m_stop_signo == SIGTERM)
{
- m_p->m_stop = false;
+ yaz_log(YLOG_LOG, "metaproxy received SIGTERM");
+ if (m_p->az)
+ {
+ size_t i;
+ for (i = 0; i < m_p->m_ports.size(); i++)
+ {
+ m_p->pdu[i]->shutdown();
+ m_p->az[i]->server("");
+ }
+ yaz_daemon_stop();
+ }
+ break; /* stop right away */
+ }
+#ifndef WIN32
+ if (m_p->m_stop_signo == SIGUSR1)
+ { /* just stop listeners and cont till all sessions are done*/
+ yaz_log(YLOG_LOG, "metaproxy received SIGUSR1");
+ m_p->m_stop_signo = 0;
if (m_p->az)
{
size_t i;
for (i = 0; i < m_p->m_ports.size(); i++)
m_p->az[i]->server("");
+ yaz_daemon_stop();
}
}
+#endif
int no = m_p->mySocketManager.getNumberOfObservers();
if (no <= 1)
break;
if (!strcmp((const char *) ptr->name, "port"))
{
Port port;
- const struct _xmlAttr *attr;
- for (attr = ptr->properties; attr; attr = attr->next)
- {
- if (!strcmp((const char *) attr->name, "route"))
- port.route = mp::xml::get_text(attr);
- }
- port.port = mp::xml::get_text(ptr);
- ports.push_back(port);
+ const char *names[5] = {"route", "max_recv_bytes", "port",
+ "cert_fname", 0};
+ std::string values[4];
+
+ mp::xml::parse_attr(ptr, names, values);
+ port.route = values[0];
+ if (values[1].length() > 0)
+ port.max_recv_bytes = atoi(values[1].c_str());
+ else
+ port.max_recv_bytes = 0;
+ if (values[2].length() > 0)
+ port.port = values[2];
+ else
+ port.port = mp::xml::get_text(ptr);
+ port.cert_fname = values[3];
+ ports.push_back(port);
}
else if (!strcmp((const char *) ptr->name, "threads"))
{
m_p->m_ports = ports;
m_p->az = new yf::FrontendNet::ZAssocServer *[m_p->m_ports.size()];
+ m_p->pdu = new yazpp_1::PDU_Assoc *[m_p->m_ports.size()];
// Create yf::FrontendNet::ZAssocServer for each port
size_t i;
- for (i = 0; i<m_p->m_ports.size(); i++)
+ for (i = 0; i < m_p->m_ports.size(); i++)
+ m_p->az[i] = 0;
+ for (i = 0; i < m_p->m_ports.size(); i++)
{
// create a PDU assoc object (one per yf::FrontendNet::ZAssocServer)
yazpp_1::PDU_Assoc *as = new yazpp_1::PDU_Assoc(&m_p->mySocketManager);
+ if (m_p->m_ports[i].cert_fname.length())
+ as->set_cert_fname(m_p->m_ports[i].cert_fname.c_str());
// create ZAssoc with PDU Assoc
+ m_p->pdu[i] = as;
m_p->az[i] = new yf::FrontendNet::ZAssocServer(
as, m_p->m_ports[i].route, m_p.get());
if (m_p->az[i]->server(m_p->m_ports[i].port.c_str()))
throw yf::FilterException("Unable to bind to address "
+ std::string(m_p->m_ports[i].port));
}
+ COMSTACK cs = as->get_comstack();
+
+ if (cs && m_p->m_ports[i].max_recv_bytes)
+ cs_set_max_recv_bytes(cs, m_p->m_ports[i].max_recv_bytes);
+
}
}