diff --git a/beast/insight/impl/StatsDCollector.cpp b/beast/insight/impl/StatsDCollector.cpp index 9d6d58644..cc93689e9 100644 --- a/beast/insight/impl/StatsDCollector.cpp +++ b/beast/insight/impl/StatsDCollector.cpp @@ -204,6 +204,7 @@ private: std::string m_prefix; boost::asio::io_service m_io_service; boost::optional m_work; + boost::asio::io_service::strand m_strand; boost::asio::deadline_timer m_timer; boost::asio::ip::udp::socket m_socket; std::deque m_data; @@ -237,6 +238,7 @@ public: , m_address (address) , m_prefix (prefix) , m_work (std::ref (m_io_service)) + , m_strand (m_io_service) , m_timer (m_io_service) , m_socket (m_io_service) , m_thread (&StatsDCollectorImp::run, this) @@ -315,9 +317,9 @@ public: void post_buffer (std::string&& buffer) { - m_io_service.dispatch (std::bind ( + m_io_service.dispatch (m_strand.wrap (std::bind ( &StatsDCollectorImp::do_post_buffer, this, - std::move (buffer))); + std::move (buffer)))); } void on_send (boost::system::error_code ec, std::size_t) @@ -359,12 +361,10 @@ public: std::vector buffers; buffers.reserve (m_data.size ()); std::size_t size (0); - for (std::deque ::const_iterator iter (m_data.begin()); - iter != m_data.end(); ++iter) + for (auto const& s : m_data) { - std::string const& buffer (*iter); - std::size_t const length (buffer.size ()); - assert (! buffer.empty ()); + std::size_t const length (s.size ()); + assert (! s.empty ()); if (! buffers.empty () && (size + length) > max_packet_size) { #if BEAST_STATSDCOLLECTOR_TRACING_ENABLED @@ -377,9 +377,11 @@ public: buffers.clear (); size = 0; } - buffers.emplace_back (&buffer[0], length); + + buffers.emplace_back (&s[0], length); size += length; } + if (! buffers.empty ()) { #if BEAST_STATSDCOLLECTOR_TRACING_ENABLED