From 33f81a3a57a047326160f371f3269dfb47c59cba Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sun, 16 Apr 2017 22:00:46 +0200 Subject: Some cleanup and tweaked the statsd slightly. --- statsd/main.cpp | 13 ++++++++++++- statsd/stats.cpp | 7 ++----- statsd/stats.hpp | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'statsd') diff --git a/statsd/main.cpp b/statsd/main.cpp index d20abc3..33ab0f8 100644 --- a/statsd/main.cpp +++ b/statsd/main.cpp @@ -7,7 +7,18 @@ #include +#include + +boost::asio::io_service io_service{}; + +void int_handler(int) { + io_service.stop(); +} + int main(int argc, char* argv[]) { + + std::signal(SIGINT, int_handler); + namespace po = boost::program_options; init_logging(boost::log::trivial::severity_level::trace, "statsd"); @@ -39,7 +50,7 @@ int main(int argc, char* argv[]) { uint16_t port = vm["port"].as(); ListenSettings lsettings{en4, if4, en6, if6, port, false, "", "", ""}; - Stats stats(lsettings); + Stats stats(io_service, lsettings); stats.run(); diff --git a/statsd/stats.cpp b/statsd/stats.cpp index e2a6a5d..a448449 100644 --- a/statsd/stats.cpp +++ b/statsd/stats.cpp @@ -6,9 +6,6 @@ void Stats::accept_connection(std::unique_ptr&& so auto it = connections.emplace(connections.end(), std::move(socket)); it->on_done([this, it](){ connections.erase(it); - if(connections.empty()) { - server.close(); - } }); it->async_receive([it, this](cmix_proto::CMixMessage const& message) { handle_message(it, message); @@ -44,8 +41,8 @@ void Stats::handle_message(std::list::iterator it, cmix_proto::CMixMes } } -Stats::Stats(ListenSettings lsettings) -: io_service() +Stats::Stats(boost::asio::io_service& io_service, ListenSettings lsettings) +: io_service(io_service) , server(io_service, lsettings, [this](std::unique_ptr&& socket){accept_connection(std::move(socket));}) {} diff --git a/statsd/stats.hpp b/statsd/stats.hpp index b6e4bca..bcf85c5 100644 --- a/statsd/stats.hpp +++ b/statsd/stats.hpp @@ -10,7 +10,7 @@ #include class Stats { - boost::asio::io_service io_service; + boost::asio::io_service& io_service; Server server; std::list connections; @@ -27,8 +27,8 @@ class Stats { void handle_message(std::list::iterator it, cmix_proto::CMixMessage message); public: - Stats(ListenSettings lsettings); + Stats(boost::asio::io_service& io_service, ListenSettings lsettings); void run(); void output(std::string file); -}; \ No newline at end of file +}; -- cgit v1.2.3-70-g09d2