相关疑难解决方法(0)

使用Boost Asio异步等待文件描述符

我正在尝试将D-Bus与我的boost::asio应用程序集成.

D-Bus有一个API,可以枚举一组要监视的Unix文件描述符(主要是套接字,但也可以是FIFO).当那些描述符有东西需要阅读时,我应该通知D-Bus API,这样它就可以读取它们并做到这一点.

目前我这样做:

using boost::asio::posix::stream_descriptor;
void read_handle(stream_descriptor* desc, const boost::system::error_code& ec,
                 std::size_t bytes_read)
{
    if (!ec) {
        stream_descriptor::bytes_readable command(true);
        descriptor->io_control(command);
        std::size_t bytes_readable = command.get();
        std::cout << "It thinks I should read" << bytes_readable
            << " bytes" << std::endl;
    } else {
        std::cout << "There was an error" << std::endl;
    }
}

void watch_descriptor(boost::asio::io_service& ios, int file_descriptor)
{
    // Create the asio representation of the descriptor
    stream_descriptor* desc = new stream_descriptor(ios);
    desc->assign(file_descriptor);

    // Try to read 0 bytes …
Run Code Online (Sandbox Code Playgroud)

c++ boost dbus boost-asio

24
推荐指数
1
解决办法
1万
查看次数

标签 统计

boost ×1

boost-asio ×1

c++ ×1

dbus ×1