fix interface to poll(2)

This commit is contained in:
Alexandre Ratchov 2012-09-20 11:00:31 +02:00
parent e451d47880
commit f997f10b0e
1 changed files with 51 additions and 38 deletions

View File

@ -117,7 +117,7 @@ It will store at most
.Ar nbytes .Ar nbytes
bytes at the bytes at the
.Ar addr .Ar addr
location and return the number of bytes stored. location.
Unless the Unless the
.Ar nbio_flag .Ar nbio_flag
flag is set, it will block until data becomes available and flag is set, it will block until data becomes available and
@ -149,34 +149,34 @@ system call can be used to check if data can be
read from or written to the stream. read from or written to the stream.
The The
.Fn mio_pollfd .Fn mio_pollfd
function fills the array function prepares the array
.Ar pfd .Ar pfd
of of
.Va pollfd .Va pollfd
structures, used by structures for use with
.Xr poll 2 , .Xr poll 2 .
with The optimal size of the
.Ar events ; .Ar pfd
the latter is a bit-mask of array, which the caller must pre-allocate, is provided by the
.Fn mio_nfds
function.
.Pp
.Xr poll 2
will sleep until any of the
.Ar events
requested with
.Fn mio_pollfd
have occurred.
Events are represented as a bit-mask of
.Va POLLIN .Va POLLIN
and and
.Va POLLOUT .Va POLLOUT
constants; refer to constants.
The events which woke up
.Xr poll 2 .Xr poll 2
for more details. can be obtained with the
.Fn mio_pollfd
returns the number of
.Va pollfd
structures filled.
The
.Fn mio_revents .Fn mio_revents
function returns the bit-mask set by function.
.Xr poll 2
in the
.Va pfd
array of
.Va pollfd
structures.
If If
.Va POLLIN .Va POLLIN
is set, is set,
@ -188,17 +188,8 @@ is set,
.Fn mio_write .Fn mio_write
can be called without blocking. can be called without blocking.
POLLHUP may be set if an error occurs, even if POLLHUP may be set if an error occurs, even if
it is not selected with it is not requested with
.Fn mio_pollfd . .Fn mio_pollfd .
.Pp
The
.Fn mio_nfds
function returns the number of
.Va pollfd
structures the caller must preallocate in order to be sure
that
.Fn mio_pollfd
will never overrun.
.Ss Error handling .Ss Error handling
Errors related to the MIDI subsystem Errors related to the MIDI subsystem
(like hardware errors or dropped connections) and (like hardware errors or dropped connections) and
@ -212,25 +203,46 @@ argument, except
and and
.Fn mio_eof , .Fn mio_eof ,
stop working (i.e. always return 0). stop working (i.e. always return 0).
.Pp
The
.Fn mio_eof
function can be used at any stage;
it returns 0 if there's no pending error, and a non-zero
value if there's an error.
.Sh RETURN VALUES .Sh RETURN VALUES
The The
.Fn mio_open .Fn mio_open
function returns the newly created handle on success or NULL function returns the newly created handle on success or NULL
on failure. on failure.
.Pp
The The
.Fn mio_pollfd .Fn mio_pollfd
function returns 1 on success and 0 on failure. function returns the number of
.Va pollfd
structures filled.
The
.Fn mio_nfds
function returns the number of
.Va pollfd
structures the caller must preallocate in order to be sure
that
.Fn mio_pollfd
will never overrun.
.Pp
The
.Fn mio_revents
function returns the bit-mask set by
.Xr poll 2
in the
.Va pfd
array of
.Va pollfd
structures.
.Pp
The The
.Fn mio_read .Fn mio_read
and and
.Fn mio_write .Fn mio_write
functions return the number of bytes transferred. functions return the number of bytes transferred.
.Pp
The
.Fn mio_eof
function returns 0 if there's no pending error, and a non-zero
value if there's an error.
.Sh ENVIRONMENT .Sh ENVIRONMENT
.Bl -tag -width "SNDIO_DEBUGXXX" -compact .Bl -tag -width "SNDIO_DEBUGXXX" -compact
.It Ev SNDIO_DEBUG .It Ev SNDIO_DEBUG
@ -249,5 +261,6 @@ devices.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr sndiod 1 , .Xr sndiod 1 ,
.Xr poll 2 ,
.Xr midi 4 , .Xr midi 4 ,
.Xr sndio 7 .Xr sndio 7