3 # Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
12 use vars qw(@ISA @EXPORT_OK @EXPORT $VERSION);
36 my $self = bless [{},{}], $class;
47 $self->[0]{$fd} ||= {};
49 $self->[0]{$fd}{$io} = $mask;
52 delete $self->[0]{$fd}{$io};
55 elsif(exists $self->[0]{$fd}{$io}) {
56 return $self->[0]{$fd}{$io};
63 my($self,$timeout) = @_;
70 while(($fd,$ref) = each %{$self->[0]}) {
72 map { $events |= $_ } values %{$ref};
73 push(@poll,$fd, $events);
76 my $ret = @poll ? _poll(defined($timeout) ? $timeout * 1000 : -1,@poll) : 0;
82 my($fd,$got) = splice(@poll,0,2);
83 $self->[1]{$fd} = $got
95 exists $self->[1]{$fd} && exists $self->[0]{$fd}{$io}
96 ? $self->[1]{$fd} & $self->[0]{$fd}{$io}
109 return map { keys %$_ } values %{$self->[0]}
112 my $events = shift || 0;
113 my($fd,$ev,$io,$mask);
116 while(($fd,$ev) = each %{$self->[1]}) {
118 while(($io,$mask) = each %{$self->[0][$fd]}) {
133 IO::Poll - Object interface to system poll call
137 use IO::Poll qw(POLLRDNORM POLLWRNORM POLLIN POLLHUP);
139 $poll = new IO::Poll;
141 $poll->mask($input_handle => POLLRDNORM | POLLIN | POLLHUP);
142 $poll->mask($output_handle => POLLWRNORM);
144 $poll->poll($timeout);
146 $ev = $poll->events($input);
150 C<IO::Poll> is a simple interface to the system level poll routine.
156 =item mask ( IO [, EVENT_MASK ] )
158 If EVENT_MASK is given, then, if EVENT_MASK is non-zero, IO is added to the
159 list of file descriptors and the next call to poll will check for
160 any event specified in EVENT_MASK. If EVENT_MASK is zero then IO will be
161 removed from the list of file descriptors.
163 If EVENT_MASK is not given then the return value will be the current
164 event mask value for IO.
166 =item poll ( [ TIMEOUT ] )
168 Call the system level poll routine. If TIMEOUT is not specified then the
169 call will block. Returns the number of handles which had events
170 happen, or -1 on error.
174 Returns the event mask which represents the events that happend on IO
175 during the last call to C<poll>.
179 Remove IO from the list of file descriptors for the next poll.
181 =item handles( [ EVENT_MASK ] )
183 Returns a list of handles. If EVENT_MASK is not given then a list of all
184 handles known will be returned. If EVENT_MASK is given then a list
185 of handles will be returned which had one of the events specified by
186 EVENT_MASK happen during the last call ti C<poll>
192 L<poll(2)>, L<IO::Handle>, L<IO::Select>
196 Graham Barr. Currently maintained by the Perl Porters. Please report all
197 bugs to <perl5-porters@perl.org>.
201 Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
202 This program is free software; you can redistribute it and/or
203 modify it under the same terms as Perl itself.