Add ASIO strand to StatsDCollector

This commit is contained in:
Miguel Portilla
2014-06-24 15:47:46 -04:00
committed by Vinnie Falco
parent 875f4c87ff
commit 0a93f8db22

View File

@@ -204,6 +204,7 @@ private:
std::string m_prefix;
boost::asio::io_service m_io_service;
boost::optional <boost::asio::io_service::work> m_work;
boost::asio::io_service::strand m_strand;
boost::asio::deadline_timer m_timer;
boost::asio::ip::udp::socket m_socket;
std::deque <std::string> 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 <boost::asio::const_buffer> buffers;
buffers.reserve (m_data.size ());
std::size_t size (0);
for (std::deque <std::string>::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