X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_limit.cpp;h=0117bf9d752e7b651552b3ba3bdde6adc3003a67;hb=9a318d33c4c99ee4158d39e3a62988af0229d7cf;hp=b97d3f00a9b630380fd3d6fc4cc3d6e48a094eac;hpb=b0c61b7f8b17d876c88347a96c246c47493140da;p=metaproxy-moved-to-github.git diff --git a/src/filter_limit.cpp b/src/filter_limit.cpp index b97d3f0..0117bf9 100644 --- a/src/filter_limit.cpp +++ b/src/filter_limit.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2010 Index Data + Copyright (C) 2005-2012 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 @@ -22,8 +22,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include -#include "package.hpp" -#include "util.hpp" +#include +#include +#ifdef WIN32 +#include +#endif namespace mp = metaproxy_1; namespace yf = mp::filter; @@ -65,7 +68,8 @@ yf::Limit::~Limit() { // must have a destructor because of boost::scoped_ptr } -void yf::Limit::configure(const xmlNode *xmlnode, bool test_only) +void yf::Limit::configure(const xmlNode *xmlnode, bool test_only, + const char *path) { m_p->configure(xmlnode); } @@ -124,9 +128,7 @@ void yf::Limit::Impl::configure(const xmlNode *ptr) void yf::Limit::Impl::process(mp::Package &package) { - package.move(); - int reduce = 0; - + int sz = 0; { boost::mutex::scoped_lock scoped_lock(m_session_mutex); @@ -142,14 +144,11 @@ void yf::Limit::Impl::process(mp::Package &package) m_sessions[package.session()] = ses; } - int sz = package.request().get_size() + package.response().get_size(); - - ses->bw_stat.add_bytes(sz); - ses->pdu_stat.add_bytes(1); - + Z_GDU *gdu = package.request().get(); if (gdu && gdu->which == Z_GDU_Z3950) { + sz += package.request().get_size(); // we're getting a Z39.50 package Z_APDU *apdu = gdu->u.z3950; if (apdu->which == Z_APDU_searchRequest) @@ -165,6 +164,28 @@ void yf::Limit::Impl::process(mp::Package &package) } } } + } + package.move(); + int reduce = 0; + { + boost::mutex::scoped_lock scoped_lock(m_session_mutex); + + yf::Limit::Ses *ses = 0; + + std::map::iterator it = + m_sessions.find(package.session()); + if (it != m_sessions.end()) + ses = it->second; + else + { + ses = new yf::Limit::Ses; + m_sessions[package.session()] = ses; + } + + sz += package.response().get_size(); + + ses->bw_stat.add_bytes(sz); + ses->pdu_stat.add_bytes(1); int bw_total = ses->bw_stat.get_total(); int pdu_total = ses->pdu_stat.get_total(); @@ -191,7 +212,11 @@ void yf::Limit::Impl::process(mp::Package &package) if (reduce) { yaz_log(YLOG_LOG, "sleeping %d seconds", reduce); +#ifdef WIN32 + Sleep(reduce * 1000); +#else sleep(reduce); +#endif } }