STREAMS Programming Guide


The M_ERROR message is sent upstream by modules or drivers to report a downstream error condition. When the message reaches the stream head, the stream is marked so that all subsequent system calls issued to the stream, excluding close(2) and poll(2), fail with errno set to the first data byte of the message. POLLERR is set if the stream is being polled. All processes sleeping on a system call to the stream are awakened. An M_FLUSH message with FLUSHRW is sent downstream.

The stream head maintains two error fields, one for the read side and one for the write side. The one-byte format M_ERROR message sets both of these fields to the error specified by the first byte in the message.

There is also a two-byte format of the M_ERROR message. The first byte is the read error and the second byte is the write error. This enables modules to set a different error on the read side and write side. If one of the bytes is set to NOERROR, then the field for the corresponding side of the stream is unchanged. The module can then ignore an error on one side of the stream. For example, if the stream head was not in an error state and a module sent an M_ERROR message upstream with the first byte set to EPROTO and the second byte set to NOERROR, all subsequent read-like system calls (such as read(2)and getmsg(2)) fail with EPROTO, but all write-like system calls (such as write(2) and putmsg(2)) still succeed. If a byte is set to 0, the error state is cleared for the corresponding side of the stream. The values NOERROR and 0 are not valid for the one-byte form of the M_ERROR message.