The io
namespace provides functions that read and
write data. You might think that reading and writing binary data is
just a matter of using the read
(2) and
write
(2). There are complications however:
read/write are allowed to do only partial data transfers. To correctly use them in all circumstances (e.g. on pipes, fifos or sockets), you need to loop until either an endfile is seen or until the desired number of bytes have been transferred.
read/write can be interrupted when the process handles a signal.
If this happens while the operation is waiting (e.g. read on a blocking
socket that has no data), the operation returns -1
but the fact that errno
is EINTR
(or in some circumstances EAGAIN) mean that
the read didn't actually fail but just must be retried.
Finally if the file descriptor has been set to non blocking
mode but you really want to get data, you may need to
loop over successive occurences of return values of
-1 and errno
values of
EWOULDBLOCK (yes you should just set the
fd to blocking mode but that presupposes that the segment
of code doing the read/write knows the socket is nonblocking).
The functions in the io
namespace
transparently handle these complications. Furthermore, in fine
C++ fashion, actual errors are converted to integer exceptions whose
value is errno
at the time the error is detected.
To use the I/O namespace functions, include io.h and link to libdaqshm. Full reference material is in io.