Discussion:
[asio-users] Monitor multiple files on Linux/C++
c***@evidence.eu.com
2011-08-01 05:20:06 UTC
Permalink
Hi all,

I am looking for a solution to monitor multiple file descriptors in C++
on Linux.

The problem: on Linux I need to monitor multiple files on /dev/,
waiting until one or more of the files become "ready" for input.

On POSIX this problem is performed by select() or poll() on a list of
file descriptors.

Many people told me that the ASIO library may be the solution to this
problem, but the ASIO documentation does not cover these aspects (i.e.,
in general it is concerned with netowrk programming rather than with
files).

Can you please tell me if ASIO can actually be used to monitor multiple
file descriptors lke select() does on POSIX ?

If so, can you please give me a piece of code to understand how to do
that ?

Many thanks,

Claudio
Igor R
2011-08-01 09:26:55 UTC
Permalink
Post by c***@evidence.eu.com
I am looking for a solution to monitor multiple file descriptors in C++
on Linux.
The problem: on Linux I need to monitor multiple files on /dev/,
waiting until one or more of the files become "ready" for input.
On POSIX this problem is performed by select() or poll() on a list of
file descriptors.
Many people told me that the ASIO library may be the solution to this
problem, but the ASIO documentation does not cover these aspects (i.e.,
in general it is concerned with netowrk programming rather than with
files).
Can you please tell me if ASIO can actually be used to monitor multiple
file descriptors lke select() does on POSIX ?
If so, can you please give me a piece of code to understand how to do
that ?
You can take a look at the following:
http://lists.boost.org/Archives/boost/2008/10/143892.php
Max M.
2011-08-01 12:36:44 UTC
Permalink
Post by c***@evidence.eu.com
The problem: on Linux I need to monitor multiple files on /dev/,
waiting until one or more of the files become "ready" for input.
1. To use Linux native file descriptors within an ASIO application, you
shoud use "posix::stream_descriptor"
2. To have an io_service behave like a "reactor" (that is, you just get
notified when you can read or write without blocking), you should use
"null_buffers".

See:

-
http://think-async.com/Asio/boost_asio_1_4_8/doc/html/boost_asio/overview/posix/stream_descriptor.html
-
http://think-async.com/Asio/boost_asio_1_4_8/doc/html/boost_asio/overview/core/reactor.html

Max

Loading...