#include <react/fd.h>
int react_prime_fd(react_t, int fd, react_iomode_t m);
int react_prime_fdin(react_t, int fd);
int react_prime_fdout(react_t, int fd);
int react_prime_fdexc(react_t, int fd);
When m
is
react_MIN
,
react_MOUT
or
react_MEXC
, the
handle will be queued when descriptor
fd
can be read
from, written to, or accessed for
exceptional events, without blocking. The
other functions simply use a hard-wired
mode as indicated by their names.
#include <react/fd.h>
int react_prime_read(react_t, int fd, void *buf, size_t len,
ssize_t *rc, int *en);
The handle will be queued when [1,
len
] bytes have
been read from fd
into the array at buf
. The number of bytes read
is stored in *rc
.
If EOF
was detected, *rc
will be zero. On error, *rc
will be -1
, and *en
will contain the error
code.
#include <react/fd.h>
int react_prime_write(react_t, int fd, const void *buf, size_t len,
ssize_t *rc, int *en);
The handle will be queued when [1,
len
] bytes have
been written to fd
from the array at buf
. The number of bytes
written is stored in *rc
. On error, *rc
will be -1
, and *en
will contain the error
code.
#include <sys/uio.h>
#include <react/fd.h>
int react_prime_readv(react_t, int fd, const struct iovec *iov,
int niovs, ssize_t *rc, int *en);
The handle will be queued when at
least one byte has been read from
fd
into the
buffers specified by iov[0]
…iov[niovs-1]
. The number of
bytes read is stored in *rc
. If EOF was detected,
*rc
will be zero.
On error, *rc
will
be -1
, and
*en
will contain
the error code.
#include <sys/uio.h>
#include <react/fd.h>
int react_prime_writev(react_t, int fd, const struct iovec *iov,
int niovs, ssize_t *rc, int *en);
The handle will be queued when at
least one byte from the buffers specified
by iov[0]
…iov[niovs-1]
has been written
to fd
. The number
of bytes written is stored in
*rc
. On error,
*rc
will be
-1
, and
*en
will contain
the error code.
#include <sys/select.h>
#include <react/fd.h>
int react_prime_fds(react_t, int nfds,
fd_set *in, fd_set *out, fd_set *exc);
The handle will be queued when at
least one of the descriptors in
*in
, *out
and *exc
can be accessed without
blocking. Only descriptors 0
…nfds-1
are considered in each
set. Any of in
,
out
and
exc
may be
NULL
to indicate
an empty set, but at least one descriptor
must be specified. If, due to priority,
the handle is not processed during the
call to react_yield
that queued it, it
will continue to watch for remaining
events that have not yet happened. When
processed, *in
,
*out
and
*exc
will contain
all events that were detected since it
was primed.
#include <poll.h>
#include <react/fd.h>
int react_prime_poll(react_t, int fd, short evs, short *got);
int react_prime_polls(react_t, struct pollfd *arr, nfds_t len);
With react_prime_poll
, the handle
is queued when any of the events in
evs
occur on
descriptor fd
. If
got
is not
NULL
, the actual
events that have occurred are written to
*got
. The possible
events are POLLIN
,
POLLOUT
,
etc, as specified
for poll()
.
POLLHUP
,
POLLERR
and
POLLNVAL
are
always implicitly watched for.
With react_prime_polls
, the handle
is queued if any of the events specified
in the array arr[0]
…arr[len-1]
occur. The
fd
field of each
element may be negative to be ignored,
but at least one descriptor must be
specified. The events that have occurred
on each descriptor are provided in the
corresponding field revents
.
With both of these functions, if the
handle is not processed as soon as it is
queued due to priority, it will continue
to monitor for remaining events, and
accumulate them as they happen.
#include <fcntl.h>
#include <react/fd.h>
int react_prime_splice(react_t,
int fd_in, loff_t *off_in,
int fd_out, loff_t *off_out, size_t max,
unsigned flags, ssize_t *rc, int *en);
int react_prime_splice_writefirst(react_t,
int fd_in, loff_t *off_in,
int fd_out, loff_t *off_out, size_t max,
unsigned flags, ssize_t *rc, int *en);
int react_prime_splice_dual(react_t,
int fd_in, loff_t *off_in,
int fd_out, loff_t *off_out, size_t max,
unsigned flags, ssize_t *rc, int *en);
The handle will be queued when
fd_out
has become
writable, and fd_in
becomes readable, and
upto max
bytes
have been moved from fd_in
to fd_out
. The number moved is
written to *rc
, or
negative on error, with *en
containing the error code.
*off_in
must be an
offset to read from, or off_in
must be NULL
. *off_out
must be an offset to
write to, or off_out
must be NULL
. *off_in
and *off_out
will be updated by
the number of bytes moved.
react_prime_slice_dual
uses
react_prime_polls
(or react_prime_fds
if
poll
is not
available ) internally to monitor both
descriptors simultaneously. If only one
event occurs, it remembers it, and waits
only for the remainder. react_prime_slice
is an alias
macro for react_prime_slice_dual
.
react_prime_slice_writefirst
first waits for the output descriptor to
become writable, then for the input to
become readable, so it always takes two
events. It is retained as the original
implementation.
*rc
takes on
the following error codes:
-1
- The error was generated by the
internal call to
splice
.
-2
- The error was due to internal
repriming of the event on the input
descriptor.
-3
- The error was due to internal
repriming of the event on the output
descriptor.
-4
- An unexpected event ocurred on the
input descriptor. Note that en error
might also have occurred on the output
descriptor.
-5
- An unexpected event ocurred on the
output descriptor. Note that en error
might also have occurred on the input
descriptor.