C-like ugliness of Kernel#select

Discussion in 'Ruby' started by C Erler, Jun 28, 2005.

  1. C Erler

    C Erler Guest

    ------=_Part_3622_25823318.1119982586853
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: inline

    IO has such methods as #closed? and #eof? to find much-needed information=
    =20
    about IO status, but it doesn't have anything like #read_ready? or=20
    #write_ready? that would be useful for anyone not wanting blocking IO. The=
    =20
    only way to do this is with the C-like ugly-hackishness that is=20
    Kernel#select.

    Does anyone have a good argument for not adding a few more methods to IO in=
    =20
    the Ruby distribution itself ? Does anybody think it would be a good idea t=
    o=20
    submit this as an RCR ? If those are added, would we be able to remove=20
    Kernel#select in the next "we don't care about backward compatibility" Ruby=
    =20
    version ?

    ------=_Part_3622_25823318.1119982586853--
     
    C Erler, Jun 28, 2005
    #1
    1. Advertising

  2. C Erler

    Jacob Fugal Guest

    On 6/28/05, C Erler <> wrote:
    > IO has such methods as #closed? and #eof? to find much-needed information
    > about IO status, but it doesn't have anything like #read_ready? or
    > #write_ready? that would be useful for anyone not wanting blocking IO. Th=

    e
    > only way to do this is with the C-like ugly-hackishness that is
    > Kernel#select.
    >=20
    > Does anyone have a good argument for not adding a few more methods to IO
    > in the Ruby distribution itself ?


    Not me.

    > Does anybody think it would be a good idea to submit this as an RCR ?


    Go ahead. After submitting it, announce the RCR in ruby-core as well
    and let the vote decide. Myself, I'm for adding a few convenience
    methods as a wrapper to specific select calls.

    > If those are added, would we be able to remove Kernel#select in the next
    > "we don't care about backward compatibility" Ruby version ?


    I wouldn't go that far. As I said above, I would probably implement
    the convenience methods as wrappers to select, unless performance
    issues were to require a lower level implementation. And leaving
    access to the unwrapped select would be nearly essential to many
    useful libraries.

    Jacob Fugal
     
    Jacob Fugal, Jun 28, 2005
    #2
    1. Advertising

  3. On Wed, 2005-06-29 at 03:16 +0900, C Erler wrote:
    > IO has such methods as #closed? and #eof? to find much-needed information
    > about IO status, but it doesn't have anything like #read_ready? or
    > #write_ready? that would be useful for anyone not wanting blocking IO. The
    > only way to do this is with the C-like ugly-hackishness that is
    > Kernel#select.


    Look in RAA for io-wait.

    > Does anyone have a good argument for not adding a few more methods to IO in
    > the Ruby distribution itself ? Does anybody think it would be a good idea to
    > submit this as an RCR ?


    It could be useful.

    > If those are added, would we be able to remove
    > Kernel#select in the next "we don't care about backward compatibility" Ruby
    > version ?


    No. Kernel#select would still be useful to wait on many IO streams at
    once.

    Guillaume.
     
    Guillaume Marcais, Jun 28, 2005
    #3
  4. C Erler

    Ara.T.Howard Guest

    On Wed, 29 Jun 2005, C Erler wrote:

    > IO has such methods as #closed? and #eof? to find much-needed information
    > about IO status, but it doesn't have anything like #read_ready? or
    > #write_ready? that would be useful for anyone not wanting blocking IO. The
    > only way to do this is with the C-like ugly-hackishness that is
    > Kernel#select.
    >
    > Does anyone have a good argument for not adding a few more methods to IO in
    > the Ruby distribution itself ? Does anybody think it would be a good idea to
    > submit this as an RCR ? If those are added, would we be able to remove
    > Kernel#select in the next "we don't care about backward compatibility" Ruby
    > version ?


    harp:~ > cat a.rb
    require 'io/wait'
    STDOUT.sync = true
    pipe = IO::popen 'while true;do sleep 2; echo 42; done'
    threads = []
    threads << Thread::new{ loop{ puts "not blocked @ <#{ Time::now }>"; sleep 0.42 } }
    threads << Thread::new{ loop{ (pipe.ready? and puts("buf <#{ pipe.gets.chomp }>")) or sleep 0.42 } }
    threads.each{|t| t.join}


    harp:~ > ruby a.rb
    not blocked @ <Tue Jun 28 14:52:45 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:45 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:46 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:46 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:47 MDT 2005>
    buf <42>
    not blocked @ <Tue Jun 28 14:52:47 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:48 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:48 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:48 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:49 MDT 2005>
    buf <42>
    not blocked @ <Tue Jun 28 14:52:49 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:50 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:50 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:51 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:51 MDT 2005>
    buf <42>
    not blocked @ <Tue Jun 28 14:52:51 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:52 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:52 MDT 2005>
    not blocked @ <Tue Jun 28 14:52:53 MDT 2005>
    buf <42>
    not blocked @ <Tue Jun 28 14:52:53 MDT 2005>
    ...
    ...
    ...

    know yer standard libs ;-) i don't think this work on windows - but it is in
    the standard dist.

    hth.

    -a
    --
    ===============================================================================
    | email :: ara [dot] t [dot] howard [at] noaa [dot] gov
    | phone :: 303.497.6469
    | My religion is very simple. My religion is kindness.
    | --Tenzin Gyatso
    ===============================================================================
     
    Ara.T.Howard, Jun 28, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yogesh
    Replies:
    3
    Views:
    614
    Kenny McCormack
    Feb 12, 2006
  2. Jon Smirl

    kernel#select and threads

    Jon Smirl, Dec 23, 2005, in forum: Ruby
    Replies:
    3
    Views:
    126
    Bill Kelly
    Dec 24, 2005
  3. Replies:
    3
    Views:
    190
  4. Lars Gierth
    Replies:
    6
    Views:
    245
    David Masover
    Mar 20, 2010
  5. Jorge

    Math ugliness.

    Jorge, Feb 16, 2010, in forum: Javascript
    Replies:
    60
    Views:
    662
    Jorge
    Feb 26, 2010
Loading...

Share This Page