non-blocking io

A

Ara.T.Howard

rubyists-

i've got some code for which i need to implement non-blocking io. i do this
so seldomly that i always have to google clr and read about doing it.
considering that ruby's thread model at times requires nbio it seems like a
'standard' method/lib of accomplishing this safely (handling appropriate
signals, etc) should be out there. anyone know of such a beast? right now
i'm looking at

http://raa.ruby-lang.org/list.rhtml?name=io-wait

but would like to avoid c extensions for this particular application.

any reason why something like io-wait would not be included in the standard
dist? portability i'm guessing...

any _complete_ impl of non-blocking io in sources from the RAA that could be
reccomended for study?

thanks.

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 
T

ts

A> any reason why something like io-wait would not be included in the standard
A> dist? portability i'm guessing...

svg% ruby -vrio/wait -e 'p IO.instance_method("wait")'
ruby 1.8.0 (2003-08-04) [i686-linux]
#<UnboundMethod: IO#wait>
svg%



Guy Decoux
 
A

Ara.T.Howard

Date: Sat, 13 Dec 2003 02:14:53 +0900
From: ts <[email protected]>
Newsgroups: comp.lang.ruby
Subject: Re: non-blocking io

A> any reason why something like io-wait would not be included in the standard
A> dist? portability i'm guessing...

svg% ruby -vrio/wait -e 'p IO.instance_method("wait")'
ruby 1.8.0 (2003-08-04) [i686-linux]
#<UnboundMethod: IO#wait>
svg%

great! i had tried -rio-wait. duh!

i'm still having a delima with non-blocking io:

if you use select or ready? to know that you have io, you then have some
options:

read using gets (line buffered) but you then don't know how may lines to
read before you will end up blocking the process

read using read(nil) - this will block the process forever when you are
reading from a pipe (i am)

read using read(buf_size) and non-blocking io, but NOT retrying on
EAGAIN. this seems like the only viable option but it can cause
truncation if EAGAIN is thrown while a pipe is thinking about sending
more output but hasn't yet...

what i really need is

buf = fd.read_all_available_bytes_but_do_not_block

i don't know if one can accomplish this using ready? and non-blocking reads or
not since it is unknowable what 'all available' means...

hmmm...

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

io/nonblock 4
tk file dialog and directories 3
puts(derived_from_array) 0
make MISSING=flock.o 0
[RCR] Kernel#hostname 0
pp equiv of #inspect 1
timeout w/o timeout.rb 3
[BUG] greedy gsub 1

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top