Boost::asio中的异步回调

来源:互联网 发布:淘宝童装处理图片 编辑:程序博客网 时间:2024/06/14 14:39

给出一个最简单的示例



回调函数

    void ReadHandle( const boost::system::error_code& error, // Result of operation.
                  std::size_t bytes_transferred )
    {
        if(!error)
        {
            cout<<" ReadComplete! "<<endl;
            cout<<" AnnotherRead... "<<endl;
        }
    }

初始化语法

        socket.async_read_some(buffer(Message),ReadHandle);
        if(ec)
        {
            std::cout << boost::system::system_error(ec).what() << std::endl;
        }

        iosev.run();

注意:ioservice必须调用run,不然回调时无法调用完成的。