termios & non-blocking I/O

Alex Semenyaka alexs at ratmir.ru
Wed Apr 9 04:20:56 PDT 2003


On Tue, Apr 08, 2003 at 11:49:44PM +0400, Andrey A. Chernov wrote:
> IEEE Std 1003.1-200x does not specify whether the setting of O_NONBLOCK
> takes precedence over MIN or TIME settings. Therefore, if O_NONBLOCK is
> set, read( ) may return immediately, regardless of the setting of MIN or
> TIME. Also, if no data is available, read( ) may either return 0, or
> return -1 with errno set to [EAGAIN].

Right you are, but the question is a little bit different, namely - what is
_better_ to do: to return 0 or to return -1/EAGAIN. Now the first choice
is implemented. And the point IS that in multi-thread environment with
utheads such implementation leads to BAD results. The progarm considers the
descriptor as being in blocking mode while libc_r hiddenly (for user) set
it up to non-blocking operation mode. So 0 returned to the program can be
considered only as EOF while it is NOT. And is IS definitely the WRONG
behaviour.

Sure user's thread system cannot deal with the descriptors in blocking mode.
But it should simulate it somehow. Yar described the example when the such
simulation is totally broken.

								SY, Alex


More information about the freebsd-arch mailing list