STREAMS-UX Programmer's Guide (February 2007)
STREAMS Mechanism and System Calls
Reading From a Stream
Chapter 2
25
Reading From a Stream
User applications can read from a stream or a STREAMS-based pipe using the read (2), readv (2), getmsg
(2), or getpmsg (2) system calls.
read(2) and readv(2)
The read (2) and readv (2) system calls are used by user applications to read message data from a stream. By
default, control data will be ignored by these calls.
Synopsis
#include <unistd.h>
size_t read (int fd, void *buf,size_t nbytes);
#include <sys/uio.h>
size_t readv (int fd, const struct iovec *iov, int iovcnt);
Arguments
fd STREAMS file descriptor.
buf Pointer to the user buffer into which the data will be read.
nbytes Number of bytes requested from the stream.
iov The data from the stream read into iov array.
iovcnt Number of elements in the iov array.
iovec A structure consists of a base address (iov_base) and a byte length (iovlen) of an area in
the memory. The readv (2) function always fills an iovec member completely before moving
on to the next. The iovec structure is as follows:
struct iovec {
void *iov_base; /* Starting address */
size_t iov_len; /* Number of bytes */
};
readv (2) also behaves the same way as read (2), except that it places the data read from the stream into
buffers specified by members of the struct iovec array (iov[0], iov[1], . . .iov[iovcnt-1]). The iovcnt is
valid if it is greater than 0 and less than or equal to {IOV_MAX}.
Read Modes
The read (2) can be executed in one of the following three modes:
•Byte-stream mode
• Message-nondiscard mode
• Message-discard mode
All streams are opened with a default of byte-stream mode. You can modify the mode using the I_SRDOPT
ioctl (2) command, and verify it using the I_GRDOPT ioctl (2) command.
Byte-Stream Mode: