Exemplo n.º 1
0
 void send_from_queue(std::shared_ptr<Connection> connection) {
     strand.post([this, connection]() {
         boost::asio::async_write(*socket, send_queue.begin()->header_stream->streambuf,
                 strand.wrap([this, connection](const boost::system::error_code& ec, size_t /*bytes_transferred*/) {
             if(!ec) {
                 boost::asio::async_write(*socket, send_queue.begin()->message_stream->streambuf,
                         strand.wrap([this, connection]
                         (const boost::system::error_code& ec, size_t /*bytes_transferred*/) {
                     auto send_queued=send_queue.begin();
                     if(send_queued->callback)
                         send_queued->callback(ec);
                     if(!ec) {
                         send_queue.erase(send_queued);
                         if(send_queue.size()>0)
                             send_from_queue(connection);
                     }
                     else
                         send_queue.clear();
                 }));
             }
             else {
                 auto send_queued=send_queue.begin();
                 if(send_queued->callback)
                     send_queued->callback(ec);
                 send_queue.clear();
             }
         }));
     });
 }
Exemplo n.º 2
0
Arquivo: main.cpp Projeto: CCJY/coliru
 void Wait() {
     if (!queue_.empty()) {
         std::cout << "t0 + " << std::setw(4) << mark() << "ms Open for Number :   "  << type <<  " (dur:"  << queue_.front() <<  ") (depth " << queue_.size() << ")\n";
         timer_.expires_from_now(boost::posix_time::milliseconds(queue_.front()));
         timer_.async_wait(strand_.wrap(std::bind(&Session::Close, shared_from_this())));
     }
 }