私のboost::asio
アプリケーションにD-Busを統合しようとしています。Boost Asioを使用したファイルディスクリプタでの非同期待機
D-Busには、監視対象となるUnixファイルディスクリプタ(主にソケットですが、FIFOでも構いません)のセットを列挙するAPIがあります。 これらのディスクリプタに何かがある場合は、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 just to be informed that there is something to be read
std::vector<char> buffer(0);
desc->async_read_some(boost::asio::buffer(buffer, 0),
boost::bind(read_handle, desc, _1, _2));
}
しかしハンドラは、それを読み取ることが0バイトであると言ってすぐに呼ばれています。読みたいものがあるときだけ呼び出されるようにしたいですが、boost :: asio を読んでください。それは賛美されたように行動するべきですselect()
。それを行う簡単な方法はありますか?
PS:私のソフトウェアには広くboost::asio
を使用していますが、これはほんの一部であるため、glib
または他のメインループには依存しません。
使用しているD-Bus APIとは何ですか?低レベルのC APIですか? –