The Linux Programming Interface

(nextflipdebug5) #1
Alternative I/O Models 1351

system call returns in the range –1 to –4095 as indicating an error, copies this (abso-
lute) value into errno, and returns –1 as the function result for the application pro-
gram. This technique is generally sufficient for dealing with the few system call
service routines that can return a valid negative result; the fcntl() F_GETOWN operation
is the only practical case where it fails. This limitation means that an application
that uses process groups to receive “I/O possible” signals (which is unusual) can’t
reliably use F_GETOWN to discover which process group owns a file descriptor.

Since glibc version 2.11, the fcntl() wrapper function fixes the problem of F_GETOWN
with process group IDs less than 4096. It does this by implementing F_GETOWN in
user space using the F_GETOWN_EX operation (Section 63.3.2), which is provided
by Linux 2.6.32 and later.

63.3.1 When Is “I/O Possible” Signaled?


We now consider the details of when “I/O possible” is signaled for various file types.

Terminals and pseudoterminals
For terminals and pseudoterminals, a signal is generated whenever new input becomes
available, even if previous input has not yet been read. “Input possible” is also sig-
naled if an end-of-file condition occurs on a terminal (but not on a pseudoterminal).
There is no “output possible” signaling for terminals. A terminal disconnect is
also not signaled.
Starting with kernel 2.4.19, Linux provides “output possible” signaling for the
slave side of a pseudoterminal. This signal is generated whenever input is consumed on
the master side of the pseudoterminal.

Pipes and FIFOs
For the read end of a pipe or FIFO, a signal is generated in these circumstances:

z Data is written to the pipe (even if there was already unread input available).
z The write end of the pipe is closed.

For the write end of a pipe or FIFO, a signal is generated in these circumstances:

z A read from the pipe increases the amount of free space in the pipe so that it is
now possible to write PIPE_BUF bytes without blocking.
z The read end of the pipe is closed.

Sockets
Signal-driven I/O works for datagram sockets in both the UNIX and the Internet
domains. A signal is generated in the following circumstances:

z An input datagram arrives on the socket (even if there were already unread
datagrams waiting to be read).
z An asynchronous error occurs on the socket.
Free download pdf