Professional Web Applications Themes

non-blocking io - Ruby

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 ...

  1. #1

    Default non-blocking io


    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'
    ================================================== =============================

    Ara.T.Howard Guest

  2. #2

    Default Re: non-blocking io

    >>>>> "A" == Ara T Howard <noaa.gov> writes:

    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


    ts Guest

  3. #3

    Default Re: non-blocking io

    On Sat, 13 Dec 2003, ts wrote:
     [/ref]
    >
    > 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%[/ref]

    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'
    ================================================== =============================

    Ara.T.Howard Guest

Similar Threads

  1. Will Thread blocking in read() leads to process blocking?
    By Loic Domaigne in forum UNIX Programming
    Replies: 4
    Last Post: July 23rd, 12:36 PM
  2. Pop-Up Blocking
    By TL Willis in forum Windows Setup, Administration & Security
    Replies: 3
    Last Post: July 21st, 06:25 AM
  3. Blocking Refresh
    By Atrax in forum ASP Components
    Replies: 1
    Last Post: July 18th, 09:11 PM
  4. Hosts - Blocking Ads
    By in forum Windows Setup, Administration & Security
    Replies: 1
    Last Post: July 7th, 08:13 PM
  5. blocking ports 136, 137
    By Faram in forum Windows XP/2000/ME
    Replies: 2
    Last Post: July 7th, 07:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139