X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_load_balance.cpp;h=1ad761c5f4c4ce4d4c73b7ee19757bc5474b6304;hb=HEAD;hp=22088ec670448ecc5260920399f0d3265895a9e4;hpb=8ced8e7b5de3ecba12ac68ce5c5e8cddf40d800f;p=metaproxy-moved-to-github.git diff --git a/src/filter_load_balance.cpp b/src/filter_load_balance.cpp index 22088ec..1ad761c 100644 --- a/src/filter_load_balance.cpp +++ b/src/filter_load_balance.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2013 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 @@ -150,8 +150,8 @@ void yf::LoadBalance::Impl::process(mp::Package &package) // they turn out to be bad.. while (1) { - std::string target; std::list::iterator ivh = vhosts.begin(); + std::list::iterator ivh_pick = vhosts.end(); Package init_pkg(package.session(), package.origin()); init_pkg.copy_filter(package); @@ -160,7 +160,7 @@ void yf::LoadBalance::Impl::process(mp::Package &package) { boost::mutex::scoped_lock scoped_lock(m_mutex); - for (; ivh != vhosts.end(); ) + for (; ivh != vhosts.end(); ivh++) { if ((*ivh).size() != 0) { @@ -170,21 +170,17 @@ void yf::LoadBalance::Impl::process(mp::Package &package) (*ivh).c_str(), cost, vhcost); if (cost > vhcost) { + ivh_pick = ivh; cost = vhcost; - target = *ivh; - ivh = vhosts.erase(ivh); } - else - ivh++; } - else - ivh++; } } - if (target.length() == 0) + if (ivh_pick == vhosts.end()) break; + std::string target = *ivh_pick; + vhosts.erase(ivh_pick); // copying new target into init package - yazpp_1::GDU init_gdu(base_req); Z_InitRequest *init_req = init_gdu.get()->u.z3950->u.initRequest;