home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / IO::Select.Z / IO::Select
Encoding:
Text File  |  1998-10-28  |  5.7 KB  |  199 lines

  1.  
  2.  
  3.  
  4.      IIIIOOOO::::::::SSSSeeeelllleeeecccctttt((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     IIIIOOOO::::::::SSSSeeeelllleeeecccctttt((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       IO::Select - OO interface to the select system call
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.           use IO::Select;
  13.  
  14.           $s = IO::Select->new();
  15.  
  16.           $s->add(\*STDIN);
  17.           $s->add($some_handle);
  18.  
  19.           @ready = $s->can_read($timeout);
  20.  
  21.           @ready = IO::Select->new(@handles)->read(0);
  22.  
  23.  
  24.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  25.       The IO::Select package implements an object approach to the
  26.       system select    function call. It allows the user to see what
  27.       IO handles, see the _I_O::_H_a_n_d_l_e manpage, are ready for
  28.       reading, writing or have an error condition pending.
  29.  
  30.      CCCCOOOONNNNSSSSTTTTRRRRUUUUCCCCTTTTOOOORRRR
  31.       new (    [ HANDLES ] )
  32.           The constructor creates a    new object and optionally
  33.           initialises it with a set    of handles.
  34.  
  35.      MMMMEEEETTTTHHHHOOOODDDDSSSS
  36.       add (    HANDLES    )
  37.           Add the list of handles to the IO::Select    object.    It is
  38.           these values that    will be    returned when an event occurs.
  39.           IO::Select keeps these values in a cache which is
  40.           indexed by the fileno of the handle, so if more than one
  41.           handle with the same fileno is specified then only the
  42.           last one is cached.
  43.  
  44.           Each handle can be an IO::Handle object, an integer or
  45.           an array reference where the first element is a
  46.           IO::Handle or an integer.
  47.  
  48.       remove ( HANDLES )
  49.           Remove all the given handles from    the object. This
  50.           method also works    by the fileno of the handles. So the
  51.           exact handles that were added need not be    passed,    just
  52.           handles that have    an equivalent fileno
  53.  
  54.       exists ( HANDLE )
  55.           Returns a    true value (actually the handle    itself)    if it
  56.           is present.  Returns undef otherwise.
  57.  
  58.       handles
  59.           Return an    array of all registered    handles.
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      IIIIOOOO::::::::SSSSeeeelllleeeecccctttt((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     IIIIOOOO::::::::SSSSeeeelllleeeecccctttt((((3333))))
  71.  
  72.  
  73.  
  74.       can_read ( [ TIMEOUT ] )
  75.           Return an    array of handles that are ready    for reading.
  76.           TIMEOUT is the maximum amount of time to wait before
  77.           returning    an empty list. If TIMEOUT is not given and any
  78.           handles are registered then the call will    block.
  79.  
  80.       can_write ( [    TIMEOUT    ] )
  81.           Same as can_read except check for    handles    that can be
  82.           written to.
  83.  
  84.       has_error ( [    TIMEOUT    ] )
  85.           Same as can_read except check for    handles    that have an
  86.           error condition, for example EOF.
  87.  
  88.       count    ()
  89.           Returns the number of handles that the object will check
  90.           for when one of the can_ methods is called or the    object
  91.           is passed    to the select static method.
  92.  
  93.       bits()
  94.           Return the bit string suitable as    argument to the    core
  95.           _s_e_l_e_c_t() call.
  96.  
  97.       bits()
  98.           Return the bit string suitable as    argument to the    core
  99.           _s_e_l_e_c_t() call.
  100.  
  101.       select ( READ, WRITE,    ERROR [, TIMEOUT ] )
  102.           select is    a static method, that is you call it with the
  103.           package name like    new. READ, WRITE and ERROR are either
  104.           undef or IO::Select objects. TIMEOUT is optional and has
  105.           the same effect as for the core select call.
  106.  
  107.           The result will be an array of 3 elements, each a
  108.           reference    to an array which will hold the    handles    that
  109.           are ready    for reading, writing and have error conditions
  110.           respectively. Upon error an empty    array is returned.
  111.  
  112.      EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  113.       Here is a short example which    shows how IO::Select could be
  114.       used to write    a server which communicates with several
  115.       sockets while    also listening for more    connections on a
  116.       listen socket
  117.  
  118.           use IO::Select;
  119.           use IO::Socket;
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      IIIIOOOO::::::::SSSSeeeelllleeeecccctttt((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     IIIIOOOO::::::::SSSSeeeelllleeeecccctttt((((3333))))
  137.  
  138.  
  139.  
  140.           $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080);
  141.           $sel = new IO::Select( $lsn );
  142.  
  143.           while(@ready = $sel->can_read) {
  144.           foreach $fh (@ready) {
  145.               if($fh ==    $lsn) {
  146.               # Create a new socket
  147.               $new = $lsn->accept;
  148.               $sel->add($new);
  149.               }
  150.               else {
  151.               # Process socket
  152.  
  153.               # Maybe we have finished with    the socket
  154.               $sel->remove($fh);
  155.               $fh->close;
  156.               }
  157.           }
  158.           }
  159.  
  160.  
  161.      AAAAUUUUTTTTHHHHOOOORRRR
  162.       Graham Barr <_G_r_a_h_a_m._B_a_r_r@_t_i_u_k._t_i._c_o_m>
  163.  
  164.      CCCCOOOOPPPPYYYYRRRRIIIIGGGGHHHHTTTT
  165.       Copyright (c)    1995 Graham Barr. All rights reserved. This
  166.       program is free software; you    can redistribute it and/or
  167.       modify it under the same terms as Perl itself.
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.