-/* $Id: filter_frontend_net.cpp,v 1.16 2006-03-16 10:40:59 adam Exp $
- Copyright (c) 2005-2006, Index Data.
+/* $Id: filter_frontend_net.cpp,v 1.24 2007-05-09 21:23:09 adam Exp $
+ Copyright (c) 2005-2007, Index Data.
-%LICENSE%
+This file is part of Metaproxy.
+
+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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Metaproxy; see the file LICENSE. If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
*/
#include "config.hpp"
+#include "util.hpp"
#include "pipe.hpp"
#include "filter.hpp"
#include "package.hpp"
#include "thread_pool_observer.hpp"
#include "filter_frontend_net.hpp"
-#include <yaz++/z-assoc.h>
-#include <yaz++/pdu-assoc.h>
-#include <yaz++/socket-manager.h>
+#include <yazpp/z-assoc.h>
+#include <yazpp/pdu-assoc.h>
+#include <yazpp/socket-manager.h>
#include <yaz/log.h>
#include <iostream>
int m_no_threads;
std::vector<std::string> m_ports;
int m_listen_duration;
+ int m_session_timeout;
};
}
class My_Timer_Thread : public yazpp_1::ISocketObserver {
~ZAssocServer();
ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable,
mp::ThreadPoolSocketObserver *m_thread_pool_observer,
- const mp::Package *package);
+ const mp::Package *package,
+ int timeout);
private:
yazpp_1::IPDU_Observer* sessionNotify(
yazpp_1::IPDU_Observable *the_PDU_Observable,
private:
mp::ThreadPoolSocketObserver *m_thread_pool_observer;
const mp::Package *m_package;
+ int m_session_timeout;
};
}
m_session->m_no_requests--;
yazpp_1::GDU *gdu = &m_package->response();
+
if (gdu->get())
{
int len;
m_session->send_GDU(gdu->get(), &len);
}
+ else if (!m_package->session().is_closed())
+ {
+ // no response package and yet the session is still open..
+ // means that request is unhandled..
+ yazpp_1::GDU *gdu_req = &m_package->request();
+ Z_GDU *z_gdu = gdu_req->get();
+ if (z_gdu && z_gdu->which == Z_GDU_Z3950)
+ {
+ // For Z39.50, response with a Close and shutdown
+ mp::odr odr;
+ int len;
+ Z_APDU *apdu_response = odr.create_close(
+ z_gdu->u.z3950, Z_Close_systemProblem,
+ "unhandled Z39.50 request");
+
+ m_session->send_Z_PDU(apdu_response, &len);
+ m_package->session().close();
+ }
+ }
+
if (m_session->m_no_requests == 0 && m_package->session().is_closed())
delete m_session;
delete this;
m_no_requests = 0;
m_delete_flag = false;
m_package = package;
+ const char *peername = PDU_Observable->getpeername();
+ if (!peername)
+ peername = "unknown";
+ m_origin.set_tcpip_address(std::string(peername), m_session.id());
}
}
mp::ZAssocServer::ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable,
- mp::ThreadPoolSocketObserver *thread_pool_observer,
- const mp::Package *package)
- : Z_Assoc(PDU_Observable)
+ mp::ThreadPoolSocketObserver *thread_pool_observer,
+ const mp::Package *package,
+ int timeout)
+ : Z_Assoc(PDU_Observable), m_session_timeout(timeout)
{
m_thread_pool_observer = thread_pool_observer;
m_package = package;
mp::ZAssocChild *my =
new mp::ZAssocChild(the_PDU_Observable, m_thread_pool_observer,
m_package);
+ my->timeout(m_session_timeout);
return my;
}
{
m_p->m_no_threads = 5;
m_p->m_listen_duration = 0;
+ m_p->m_session_timeout = 300; // 5 minutes
}
mp::filter::FrontendNet::~FrontendNet()
yazpp_1::PDU_Assoc *as = new yazpp_1::PDU_Assoc(&mySocketManager);
// create ZAssoc with PDU Assoc
- az[i] = new mp::ZAssocServer(as, &threadPool, &package);
+ az[i] = new mp::ZAssocServer(as, &threadPool, &package,
+ m_p->m_session_timeout);
az[i]->server(m_p->m_ports[i].c_str());
}
while (mySocketManager.processEvent() > 0)
+ threads_str);
m_p->m_no_threads = threads;
}
+ else if (!strcmp((const char *) ptr->name, "timeout"))
+ {
+ std::string timeout_str = mp::xml::get_text(ptr);
+ int timeout = atoi(timeout_str.c_str());
+ if (timeout < 1)
+ throw mp::filter::FilterException("Bad value for timeout: "
+ + timeout_str);
+ m_p->m_session_timeout = timeout;
+ }
else
{
throw mp::filter::FilterException("Bad element "