X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_frontend_net.cpp;h=04322af4158d9fc1a7fcf7acf8ce0f90b91abc7d;hb=e6d572ef110d14fa55115021505b808620457bd3;hp=ac85e4177896e8e6f97c8abe4d8701c77dffc298;hpb=5760a554d57198bb0eafcb42ef98a82a49b4b8e3;p=metaproxy-moved-to-github.git diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index ac85e41..04322af 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2008 Index Data + Copyright (C) 2005-2010 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 @@ -18,15 +18,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "config.hpp" -#include "util.hpp" +#include #include "pipe.hpp" -#include "filter.hpp" -#include "package.hpp" +#include +#include #include "thread_pool_observer.hpp" #include "filter_frontend_net.hpp" #include #include #include +#include #include #include @@ -43,8 +44,8 @@ namespace metaproxy_1 { std::vector m_ports; int m_listen_duration; int m_session_timeout; + int m_connect_max; yazpp_1::SocketManager mySocketManager; - ZAssocServer **az; }; } @@ -97,7 +98,8 @@ namespace metaproxy_1 { class ZAssocServer : public yazpp_1::Z_Assoc { public: ~ZAssocServer(); - ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable, int timeout); + ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable, int timeout, + int connect_max); void set_package(const mp::Package *package); void set_thread_pool(ThreadPoolSocketObserver *m_thread_pool_observer); private: @@ -113,6 +115,8 @@ namespace metaproxy_1 { mp::ThreadPoolSocketObserver *m_thread_pool_observer; const mp::Package *m_package; int m_session_timeout; + int m_connect_max; + yazpp_1::LimitConnect limit_connect; }; } @@ -219,7 +223,8 @@ void mp::ZAssocChild::failNotify() // TODO: send Package to signal "close" if (m_session.is_closed()) { - delete this; + if (m_no_requests == 0) + delete this; return; } m_no_requests++; @@ -244,8 +249,9 @@ void mp::ZAssocChild::connectNotify() } mp::ZAssocServer::ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable, - int timeout) - : Z_Assoc(PDU_Observable), m_session_timeout(timeout) + int timeout, int connect_max) + : Z_Assoc(PDU_Observable), m_session_timeout(timeout), + m_connect_max(connect_max) { m_package = 0; } @@ -264,6 +270,16 @@ void mp::ZAssocServer::set_thread_pool(ThreadPoolSocketObserver *observer) yazpp_1::IPDU_Observer *mp::ZAssocServer::sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable, int fd) { + + const char *peername = the_PDU_Observable->getpeername(); + if (peername) + { + limit_connect.add_connect(peername); + limit_connect.cleanup(false); + int con_sz = limit_connect.get_total(peername); + if (m_connect_max && con_sz > m_connect_max) + return 0; + } mp::ZAssocChild *my = new mp::ZAssocChild(the_PDU_Observable, m_thread_pool_observer, m_package); @@ -391,6 +407,10 @@ void mp::filter::FrontendNet::configure(const xmlNode * ptr, bool test_only) + timeout_str); m_p->m_session_timeout = timeout; } + else if (!strcmp((const char *) ptr->name, "connect-max")) + { + m_p->m_connect_max = mp::xml::get_int(ptr->children, 0); + } else { throw mp::filter::FilterException("Bad element " @@ -418,7 +438,8 @@ void mp::filter::FrontendNet::set_ports(std::vector &ports) // create ZAssoc with PDU Assoc m_p->az[i] = new mp::ZAssocServer(as, - m_p->m_session_timeout); + m_p->m_session_timeout, + m_p->m_connect_max); if (m_p->az[i]->server(m_p->m_ports[i].c_str())) { throw mp::filter::FilterException("Unable to bind to address " @@ -448,8 +469,9 @@ extern "C" { /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil - * c-file-style: "stroustrup" * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +