Exemple #1
0
void Client::flush()
{
  while (mRunning)
    {
      // waits for messages to send
      boost::unique_lock<boost::mutex> lock(mWMutex);
      while (mWriteQ.empty() && mRunning)
	mWCond.wait(lock);

      if (mRunning)
	{
	  // get and remove next item
	  MessagePtr msg = mWriteQ.front();
	  mWriteQ.pop_front();
	  
	  // send it to the thread, but wait for other writes to finish
	  mWSMutex.lock();
	  boost::asio::async_write(mSocket,
				   boost::asio::buffer(msg->raw(),
						       msg->rawLength()),
				   boost::bind(&Client::onWritten,
					       this,
					       boost::asio::placeholders::error));
	}
    }
    printf("Done flushing...\n");
}