Пример #1
0
    void
    do_sync()
    {
        try
        {
            ws_.accept();
            for(;;)
            {
                ws_.read(buffer_);
                ws_.text(ws_.got_text());
                ws_.write(buffer_.data());
                buffer_.consume(buffer_.size());
            }
        }
        catch(system_error const& se)
        {
            boost::ignore_unused(se);
#if 0
            if( se.code() != error::closed &&
                se.code() != error::failed &&
                se.code() != boost::asio::error::eof)
                log_ << "ws_echo_server: " << se.code().message() << std::endl;
#endif
        }
        catch(std::exception const& e)
        {
            log_ << "ws_echo_server: " << e.what() << std::endl;
        }
    }
Пример #2
0
 void
 on_write(error_code ec)
 {
     if(ec)
         return fail(ec);
     buffer_.consume(buffer_.size());
     do_read();
 }
Пример #3
0
//[ws_snippet_21
void echo(stream<boost::asio::ip::tcp::socket>& ws,
    multi_buffer& buffer, boost::asio::yield_context yield)
{
    ws.async_read(buffer, yield);
    std::future<std::size_t> fut =
        ws.async_write(buffer.data(), boost::asio::use_future);
}
Пример #4
0
 void
 on_read(error_code ec)
 {
     if(ec)
         return fail(ec);
     ws_.text(ws_.got_text());
     ws_.async_write(buffer_.data(),
         std::bind(
             &ws_echo_server::on_write,
             this,
             std::placeholders::_1));
 }