From aff78cecdb2c7292899ae15ee8a5fd41accef2b5 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 10 Apr 2012 13:43:29 +0200 Subject: [PATCH] Beginnings of graceful stop --- include/metaproxy/filter.hpp | 2 ++ include/metaproxy/router.hpp | 1 + src/filter.cpp | 4 ++++ src/filter_frontend_net.cpp | 11 +++++++++++ src/filter_frontend_net.hpp | 1 + src/metaproxy_prog.cpp | 4 ++++ src/router_chain.cpp | 9 ++++++++- src/router_chain.hpp | 1 + src/router_flexml.cpp | 18 ++++++++++++++++++ src/router_flexml.hpp | 1 + 10 files changed, 51 insertions(+), 1 deletion(-) 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 a3ab5f7..216d740 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -375,6 +375,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() 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..ce60c60 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -52,8 +52,11 @@ static pid_t process_group = 0; static void sig_term_handler(int s) { + routerp->stop(); +#if 0 kill(-process_group, SIGTERM); /* kill all children processes as well */ _exit(0); +#endif } #endif @@ -69,6 +72,7 @@ static void handler_debug(void *data) mp::Package pack; pack.router(*routerp).move(); /* should never exit */ + _exit(0); } static void handler_normal(void *data) 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; }; -- 1.7.10.4