From: Adam Dickmeiss Date: Tue, 24 Apr 2012 13:21:56 +0000 (+0200) Subject: Merge branch 'master' into graceful_stop X-Git-Tag: v1.3.34~10 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=84c5e997dc7d9775959c953f64a330eac18a0d00;hp=36e44f62ebd8f66995eb3a3f069ea024d63246dc;p=metaproxy-moved-to-github.git Merge branch 'master' into graceful_stop --- diff --git a/include/metaproxy/filter.hpp b/include/metaproxy/filter.hpp index b42116c..2d5495f 100644 --- a/include/metaproxy/filter.hpp +++ b/include/metaproxy/filter.hpp @@ -41,6 +41,8 @@ namespace metaproxy_1 { const char *path) = 0; virtual void start() const; + + virtual void stop() const; }; class FilterException : public std::runtime_error { diff --git a/include/metaproxy/router.hpp b/include/metaproxy/router.hpp index 11c6e96..25db0cd 100644 --- a/include/metaproxy/router.hpp +++ b/include/metaproxy/router.hpp @@ -43,6 +43,7 @@ namespace metaproxy_1 virtual RoutePos *createpos() const = 0; virtual void start() = 0; + virtual void stop() = 0; }; class RoutePos : boost::noncopyable { diff --git a/src/filter.cpp b/src/filter.cpp index e625618..a195931 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -27,6 +27,10 @@ void mp::filter::Base::start() const { } +void mp::filter::Base::stop() const +{ +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index b347ad2..c0f27ef 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -126,7 +126,7 @@ namespace metaproxy_1 { void failNotify(); void timeoutNotify(); - void connectNotify(); + void connectNotify(); private: mp::ThreadPoolSocketObserver *m_thread_pool_observer; const mp::Package *m_package; @@ -383,6 +383,17 @@ mp::filter::FrontendNet::~FrontendNet() delete m_p->az[i]; delete [] m_p->az; } + m_p->az = 0; +} + +void mp::filter::FrontendNet::stop() const +{ + if (m_p->az) + { + size_t i; + for (i = 0; im_ports.size(); i++) + m_p->az[i]->server(""); + } } bool mp::My_Timer_Thread::timeout() @@ -425,6 +436,8 @@ void mp::filter::FrontendNet::process(Package &package) const } while (m_p->mySocketManager.processEvent() > 0) { + if (m_p->mySocketManager.getNumberOfObservers() <= 1) + break; if (tt && tt->timeout()) break; } diff --git a/src/filter_frontend_net.hpp b/src/filter_frontend_net.hpp index 719770f..92a6603 100644 --- a/src/filter_frontend_net.hpp +++ b/src/filter_frontend_net.hpp @@ -38,6 +38,7 @@ namespace metaproxy_1 { void process(metaproxy_1::Package & package) const; void configure(const xmlNode * ptr, bool test_only, const char *path); + void stop() const; public: /// set ports void set_ports(std::vector &ports); diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index 4f28e4f..7183419 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -50,6 +50,11 @@ mp::RouterFleXML *routerp = 0; #if HAVE_UNISTD_H static pid_t process_group = 0; +static void sig_usr1_handler(int s) +{ + routerp->stop(); +} + static void sig_term_handler(int s) { kill(-process_group, SIGTERM); /* kill all children processes as well */ @@ -57,27 +62,34 @@ static void sig_term_handler(int s) } #endif -static void handler_debug(void *data) +static void work_common(void *data) { #if HAVE_UNISTD_H process_group = getpgid(0); // save process group ID signal(SIGTERM, sig_term_handler); + signal(SIGUSR1, sig_usr1_handler); #endif routerp = (mp::RouterFleXML*) data; routerp->start(); mp::Package pack; pack.router(*routerp).move(); /* should never exit */ + _exit(0); +} + +static void work_debug(void *data) +{ + work_common(data); } -static void handler_normal(void *data) +static void work_normal(void *data) { #if HAVE_UNISTD_H /* make the current working process group leader */ setpgid(0, 0); #endif - handler_debug(data); + work_common(data); } static int sc_main( @@ -214,7 +226,7 @@ static int sc_main( yaz_sc_running(s); yaz_daemon("metaproxy", mode, mode == YAZ_DAEMON_DEBUG ? - handler_debug : handler_normal, router, pidfile, uid); + work_debug : work_normal, router, pidfile, uid); } } catch (std::logic_error &e) { diff --git a/src/router_chain.cpp b/src/router_chain.cpp index ccd0486..fa4385f 100644 --- a/src/router_chain.cpp +++ b/src/router_chain.cpp @@ -58,6 +58,14 @@ void mp::RouterChain::start() (*it)->start(); } +void mp::RouterChain::stop() +{ + std::list::const_iterator it; + + for (it = m_p->m_filter_list.begin(); it != m_p->m_filter_list.end(); it++) + (*it)->stop(); +} + const mp::filter::Base *mp::RouterChain::Pos::move(const char *route) { if (it == m_p->m_filter_list.end()) @@ -83,7 +91,6 @@ mp::RoutePos *mp::RouterChain::Pos::clone() return p; } - mp::RouterChain::Pos::~Pos() { } diff --git a/src/router_chain.hpp b/src/router_chain.hpp index 052ce0a..a395205 100644 --- a/src/router_chain.hpp +++ b/src/router_chain.hpp @@ -35,6 +35,7 @@ namespace metaproxy_1 { virtual RoutePos *createpos() const; RouterChain & append(const filter::Base &filter); void start(); + void stop(); private: boost::scoped_ptr m_p; /// disabled because class is singleton diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index 7e5bbbb..29e468b 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -503,6 +503,24 @@ void mp::RouterFleXML::start() } } +void mp::RouterFleXML::stop() +{ + std::map::iterator route_it; + + route_it = m_p->m_routes.begin(); + while (route_it != m_p->m_routes.end()) + { + RouterFleXML::Route route = route_it->second; + + std::list >::iterator it; + + for (it = route.m_list.begin(); it != route.m_list.end(); it++) + (*it)->stop(); + route_it++; + } +} + + /* * Local variables: * c-basic-offset: 4 diff --git a/src/router_flexml.hpp b/src/router_flexml.hpp index a83e1b8..2a385d7 100644 --- a/src/router_flexml.hpp +++ b/src/router_flexml.hpp @@ -44,6 +44,7 @@ namespace metaproxy_1 virtual RoutePos *createpos() const; void start(); + void stop(); private: boost::scoped_ptr m_p; };