From: Adam Dickmeiss Date: Fri, 14 Oct 2005 16:44:55 +0000 (+0000) Subject: FilterFrontendNet allows listening on multiple ports. X-Git-Tag: YP2.0.0.2~207 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=941d13b6a4dc2c2dd0e4bda89d380bfd8991b03b;p=metaproxy-moved-to-github.git FilterFrontendNet allows listening on multiple ports. Program ex_filter_frontend_net allows ports to be specified as options -- as either '--port==port=val' or just 'val'. --- diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp index 4ae21fa..23c5aa1 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -68,10 +68,15 @@ int main(int argc, char **argv) ("help", "produce help message") ("duration", po::value(), "number of seconds for server to exist") + ("port", po::value< std::vector >(), "listener port") ; + po::positional_options_description p; + p.add("port", -1); + po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); + po::store(po::command_line_parser(argc, argv). + options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { @@ -79,17 +84,23 @@ int main(int argc, char **argv) return 1; } + if (vm.count("port")) { + std::vector ports = + vm["port"].as< std::vector >(); + + for (size_t i = 0; i0 timeout in seconds if (vm.count("duration")) { - filter_front.listen_duration() = - vm["duration"].as(); + filter_front.listen_duration() = vm["duration"].as(); } router.rule(filter_front); diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index ba81508..d610cee 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -176,8 +176,9 @@ ZAssocServer::ZAssocServer(yazpp_1::IPDU_Observable *the_PDU_Observable, yazpp_1::IPDU_Observer *ZAssocServer::sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable, int fd) { - ZAssocServerChild *my = new ZAssocServerChild(the_PDU_Observable, m_thread_pool_observer, - m_package); + ZAssocServerChild *my = + new ZAssocServerChild(the_PDU_Observable, m_thread_pool_observer, + m_package); return my; } @@ -204,7 +205,6 @@ void ZAssocServer::connectNotify() FilterFrontendNet::FilterFrontendNet() { m_no_threads = 5; - m_listen_address = "@:9001"; m_listen_duration = 0; } @@ -249,25 +249,36 @@ void FilterFrontendNet::process(Package &package) const { if (m_listen_duration) tt = new My_Timer_Thread(&mySocketManager, m_listen_duration); - yazpp_1::PDU_Assoc *my_PDU_Assoc = - new yazpp_1::PDU_Assoc(&mySocketManager); - ThreadPoolSocketObserver threadPool(&mySocketManager, m_no_threads); - ZAssocServer z(my_PDU_Assoc, &threadPool, &package); - z.server(m_listen_address.c_str()); + ZAssocServer **az = new ZAssocServer *[m_ports.size()]; + + // Create ZAssocServer for each port + size_t i; + for (i = 0; iserver(m_ports[i].c_str()); + } while (mySocketManager.processEvent() > 0) { if (tt && tt->timeout()) break; } + for (i = 0; i &FilterFrontendNet::ports() { - return m_listen_address; + return m_ports; } int &FilterFrontendNet::listen_duration() diff --git a/src/filter_frontend_net.hpp b/src/filter_frontend_net.hpp index d00945f..b1c6bd4 100644 --- a/src/filter_frontend_net.hpp +++ b/src/filter_frontend_net.hpp @@ -3,6 +3,7 @@ #define FILTER_FRONEND_NET_HPP #include +#include #include "filter.hpp" @@ -13,11 +14,11 @@ namespace yp2 { void process(yp2::Package & package) const; private: int m_no_threads; - std::string m_listen_address; + std::vector m_ports; int m_listen_duration; public: /// set function - left val in assignment - std::string & listen_address(); + std::vector &ports(); int &listen_duration(); }; } diff --git a/src/test_filter_frontend_net.cpp b/src/test_filter_frontend_net.cpp index 1c9b8c2..f6b9c5d 100644 --- a/src/test_filter_frontend_net.cpp +++ b/src/test_filter_frontend_net.cpp @@ -102,7 +102,10 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 ) // put in frontend first yp2::FilterFrontendNet filter_front; - filter_front.listen_address() = "unix:socket"; + + std::vector ports; + ports.insert(ports.begin(), "unix:socket"); + filter_front.ports() = ports; filter_front.listen_duration() = 1; // listen a short time only router.rule(filter_front);