*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> perl5/IO::Select (3)              
Title
Content
Arch
Section
 

Contents


IO::Select(3)							 IO::Select(3)


NAME    [Toc]    [Back]

     IO::Select	- OO interface to the select system call

SYNOPSIS    [Toc]    [Back]

	 use IO::Select;

	 $s = IO::Select->new();

	 $s->add(\*STDIN);
	 $s->add($some_handle);

	 @ready	= $s->can_read($timeout);

	 @ready	= IO::Select->new(@handles)->read(0);

DESCRIPTION    [Toc]    [Back]

     The IO::Select package implements an object approach to the system	select
     function call. It allows the user to see what IO handles, see the
     IO::Handle	manpage, are ready for reading,	writing	or have	an error
     condition pending.

CONSTRUCTOR    [Toc]    [Back]

     new ( [ HANDLES ] )
	 The constructor creates a new object and optionally initialises it
	 with a	set of handles.

METHODS    [Toc]    [Back]

     add ( HANDLES )
	 Add the list of handles to the	IO::Select object. It is these values
	 that will be returned when an event occurs. IO::Select	keeps these
	 values	in a cache which is indexed by the fileno of the handle, so if
	 more than one handle with the same fileno is specified	then only the
	 last one is cached.

	 Each handle can be an IO::Handle object, an integer or	an array
	 reference where the first element is a	IO::Handle or an integer.

     remove ( HANDLES )
	 Remove	all the	given handles from the object. This method also	works
	 by the	fileno of the handles. So the exact handles that were added
	 need not be passed, just handles that have an equivalent fileno

     exists ( HANDLE )
	 Returns a true	value (actually	the handle itself) if it is present.
	 Returns undef otherwise.

     handles
	 Return	an array of all	registered handles.






									Page 1






IO::Select(3)							 IO::Select(3)



     can_read (	[ TIMEOUT ] )
	 Return	an array of handles that are ready for reading.	TIMEOUT	is the
	 maximum amount	of time	to wait	before returning an empty list.	If
	 TIMEOUT is not	given and any handles are registered then the call
	 will block.

     can_write ( [ TIMEOUT ] )
	 Same as can_read except check for handles that	can be written to.

     has_error ( [ TIMEOUT ] )
	 Same as can_read except check for handles that	have an	error
	 condition, for	example	EOF.

     count ()
	 Returns the number of handles that the	object will check for when one
	 of the	can_ methods is	called or the object is	passed to the select
	 static	method.

     bits()
	 Return	the bit	string suitable	as argument to the core	select() call.

     bits()
	 Return	the bit	string suitable	as argument to the core	select() call.

     select ( READ, WRITE, ERROR [, TIMEOUT ] )
	 select	is a static method, that is you	call it	with the package name
	 like new. READ, WRITE and ERROR are either undef or IO::Select
	 objects. TIMEOUT is optional and has the same effect as for the core
	 select	call.

	 The result will be an array of	3 elements, each a reference to	an
	 array which will hold the handles that	are ready for reading, writing
	 and have error	conditions respectively. Upon error an empty array is
	 returned.

EXAMPLE    [Toc]    [Back]

     Here is a short example which shows how IO::Select	could be used to write
     a server which communicates with several sockets while also listening for
     more connections on a listen socket

	 use IO::Select;
	 use IO::Socket;













									Page 2






IO::Select(3)							 IO::Select(3)



	 $lsn =	new IO::Socket::INET(Listen => 1, LocalPort => 8080);
	 $sel =	new IO::Select(	$lsn );

	 while(@ready =	$sel->can_read)	{
	     foreach $fh (@ready) {
		 if($fh	== $lsn) {
		     # Create a	new socket
		     $new = $lsn->accept;
		     $sel->add($new);
		 }
		 else {
		     # Process socket

		     # Maybe we	have finished with the socket
		     $sel->remove($fh);
		     $fh->close;
		 }
	     }
	 }

AUTHOR    [Toc]    [Back]

     Graham Barr <Graham.Barr@tiuk.ti.com>

COPYRIGHT    [Toc]    [Back]

     Copyright (c) 1995	Graham Barr. All rights	reserved. This program is free
     software; you can redistribute it and/or modify it	under the same terms
     as	Perl itself.


									PPPPaaaaggggeeee 3333
[ Back ]
 Similar pages
Name OS Title
pxfopen IRIX Provides a Fortran interface to the open(2) system call
sia_chdir Tru64 Interface to the chdir system call - SIA (Security Integration Architecture)
sgigsc IRIX SGI graphics system call
__syscall FreeBSD indirect system call
syscall FreeBSD indirect system call
syscall NetBSD indirect system call
cu IRIX call another UNIX system
__syscall OpenBSD indirect system call
syscall OpenBSD indirect system call
__syscall NetBSD indirect system call
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service