From: Tanaka Akira Date: 2003-09-02T12:05:11+09:00 Subject: Re: non-blocking mode behavior (Re: bug) In article , Mathieu Bouchard writes: > Proper behaviour for nonblocking operations is: > > * never, ever wait > > * never raise Errno::E000 ("Success"), which is always a bug > (in the past, many bugs in nonblocking mode fell in that category) > > * if nothing can be done, raise Errno::EAGAIN > > * if not all can be done, give what was received or how much was > sent, so that the operation can be resumed by the calling code > at its discretion > > * if something is buffered, then any partially-read block should > end up in the buffer; it should not be discarded. > > If any of the above is not clear or questionable or you think there > should be special cases, please inform me. Because non-blocking mode may be set by other process if opened file is shared, such blocking/nonblocking sensitive behaviour may cause problem. For example, ssh set stderr non-blocking mode and problem is caused with emacs: http://groups.google.com/groups?th=e4df2fdc1f4f4950 http://sources.redhat.com/ml/bug-glibc/2002-08/threads.html#00041 http://sources.redhat.com/ml/bug-glibc/2002-08/threads.html#00186 I think usual methods should work as blocking mode even if nonblocking mode i.e. such methods should retry the operation when EAGAIN is occured. Since sometimes nonblocking behaviour is required, such behaviour should be provided by different method such as read_nonblock/write_nonblock. They should temporally set non-blocking mode if necessary. They should work as your "proper behaviour for nonblocking operations". > I think I could migrate everything to threads, to avoid the numerous > problems in nonblocking mode, but I have to make sure I don't need to read > "as much as possible" data from a socket, because that can't be done in > threaded IO (except by a very slow loop of read(1)). Use sysread. If you want to use sysread and other IO methods, my nonstdio.rb may help you. (see RAA) -- Tanaka Akira