What's "io/nonblock"?

What's "io/nonblock"?

Post by Gavin Sinc » Sat, 17 Apr 2004 23:15:36



Chad Fowler knows what it is, and told me it's standard with 1.8.
Yippee. I reinstalled Ruby (latest CVS 1.8 branch), even though my
existing Ruby was not yet one month old, and here is the relevant
section from the output:

installing io/wait
make[1]: Entering directory `/home/gavin/Projects/ruby18/ext/io/wait'
make[1]: Nothing to be done for `install'.
make[1]: Leaving directory `/home/gavin/Projects/ruby18/ext/io/wait'

Problem, that.

Cheers,
Gavin
 
 
 

What's "io/nonblock"?

Post by Michael Gr » Sat, 17 Apr 2004 23:43:34


A problem, perhaps, but io/nonblock.rb is installed from
ext/io/wait/lib/, and is, as its name suggests, a plain Ruby file. It
doesn't appear to require io/wait, either, so you should be okay with
just installing it by itself to get 'session' working.

 
 
 

What's "io/nonblock"?

Post by Ara.T.Howa » Sun, 18 Apr 2004 01:11:21


would do - but __i__ require io/wait as well. the truth is i currently don't
really need both: my original design used nonblock, but this is broken in
threads, the lastest uses IO.ready?, which you get from io/wait:


from the source

<snip>
# this is the desired call - but threads block on it!
#iodat[:io].nonblock{ buf = iodat[:io].read }

# 2.1.5
#sleep(0.042) and Thread.pass until iodat[:io].ready?
#buf << iodat[:io].getc while iodat[:io].ready?

# 2.1.6
# decided to go ahead and read lines since
# - loop only terminates when cmd_end_pat has been found and this
# must be newline terminated
# - although this will block mid-line in the case of parital lines we
# know that, eventually, a newline will appear and this delay is
# acceptable so we can make larger (line buffered) reads instead of
# character ones. eventually i'd like to use io.nonblock{} to read
# 'as much as is there' but this does not play well with threads at the
# moment
buf << iodat[:io].gets while iodat[:io].ready?
</snip>


the semantics i'd like to have are 'read as much data as is possible, even a
single character, but don't block on the read'. this is what

iodat[:io].nonblock{ buf = iodat[:io].read }

should do. but in a thread it blocks. there was a few postings on this 2
months ago by me, nobu i think, and tanaka akira if you feel like searching...

in any case = you could acutally commnet out the 'require "io/nonblock"' and
it would be fine. but i hope to use this in future versions...

weird that you were lacking it - my old 18 seems to have it...

oh well.

cheers.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.yqcomputer.com/
| TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
===============================================================================