Refine Q9/A9.

This commit is contained in:
Michael Kerrisk 2008-02-28 13:49:29 +00:00
parent 7fb5cf0fb6
commit f11af7daa2
1 changed files with 18 additions and 20 deletions

View File

@ -377,34 +377,32 @@ when using the
flag (edge-triggered behavior) ? flag (edge-triggered behavior) ?
.TP .TP
.B A9 .B A9
The answer depends on whether the file descriptor refers to a
stream-oriented file, or to a packet/token-oriented file.
.sp
For a stream oriented file (pipe, FIFO, stream socket): no you don't.
Receiving an event from Receiving an event from
.BR epoll_wait (2) .BR epoll_wait (2)
should suggest to you that such file descriptor is ready should suggest to you that such
for the requested I/O operation. file descriptor is ready for the requested I/O operation.
You have simply to consider it ready until you will receive the You have simply to consider it ready until you receive the next
next
.BR EAGAIN . .BR EAGAIN .
When and how you will use such file descriptor is entirely up When and how you will use the file descriptor is entirely up to you.
to you. .sp
Also, the condition that the read/write I/O space is exhausted can For stream oriented files (e.g., pipe, FIFO, stream socket), the
be detected by checking the amount of data read from / written to the target condition that the read/write I/O space is exhausted can also be detected by
file descriptor. checking the amount of data read from / written to the target file
descriptor.
For example, if you call For example, if you call
.BR read (2) .BR read (2)
by asking to read a certain amount of data and by asking to read a certain amount of data and
.BR read (2) .BR read (2)
returns a lower number of bytes, returns a lower number of bytes, you
you can be sure of having exhausted the read can be sure of having exhausted the read I/O space for the file
I/O space for such file descriptor. descriptor.
The same is true when writing using The same is true when writing using
.BR write (2). .BR write (2).
.sp .sp
For a packet/token-oriented file (e.g., datagram socket, For packet/token oriented files (e.g., datagram socket,
terminal in canonical mode): yes you do. terminal in canonical mode), you need to continue to read/write until
.BR EAGAIN ,
in order to detect the end of the read/write I/O space.
.SS Possible Pitfalls and Ways to Avoid Them .SS Possible Pitfalls and Ways to Avoid Them
.TP .TP
.B o Starvation (edge-triggered) .B o Starvation (edge-triggered)