select would indicate pipe is readable when there's no data in pipe and write end is closed?
3
votes
2
answers
3311
views
I am reading *The Linux Programming Interface*.
From *63.2.3 When Is a File Descriptor Ready?*, it says:
> Correctly using
select()
and poll()
requires an understanding of
> the conditions under which a file descriptor indicates as being ready.
> SUSv3 says that a file descriptor (with O_NONBLOCK
clear) is
> considered to be ready if a call to an I/O function would not block,
> *regardless of whether the function would actually transfer data*. The key point is italicized: select()
and poll()
tell us whether an
> I/O operation would not block, rather than whether it would
> successfully transfer data. In this light, let us consider how these
> system calls operate for different types of file descriptors. We show
> this information in tables containing two columns:
>
> - The select()
column indicates whether a file descriptor is marked as readable (r), writable (w), or having an exceptional condition (x).
>
> ....
>
> Pipes and FIFOs
>
> Table 63-4 summarizes the details for the read end of a pipe or FIFO.
> The Data in pipe?
column indicates whether the pipe has at least 1
> byte of data available for reading. In this table, we assume that
> POLLIN
was specified in the events
field for poll()
.
>
> ....
>
> Table 63-4: select()
and poll()
indications for the read end of a
> pipe or FIFO
>
> Condition or event | select() | poll()
> Data in pipe? | Write end open? |
> no | no | r | POLLHUP
> yes | yes | r | POLLIN
> yes | no | r | POLLIN | POLLHUP
>
> And Table 63-5: select()
and poll()
indications for the write end
> of a pipe or FIFO
> (In this table, we
assume that POLLOUT
was specified in the events field for poll()
.)
>
> Condition or event | select() | poll()
> Space for PIPE_BUF bytes? | Read end open? |
> no | no | w | POLLERR
> yes | yes | w | POLLOUT
> yes | no | w | POLLOUT | POLLERR
I don't understand the 1st row condition of both tables.
No data in pipe, write end closed, select()
would indicate that as a readable file descriptor? Why? Shouldn't select()
block till there's data in the pipe?
No space for PIPE_BUF
bytes, read end closed, select()
would indicate that as a writeable file descriptor?
Asked by Rick
(1247 rep)
Jun 10, 2020, 02:28 AM
Last activity: Dec 12, 2022, 12:46 PM
Last activity: Dec 12, 2022, 12:46 PM