# Create the list of filedescriptors to check for activity $bits = $bobs = ''; foreach my $listen (@listeners) { vec($bits, $listen->{fd}->fileno(), 1) = 1; } # Do the business my ($rout, $wout, $eout); my $nfound = select($rout=$bits, $wout='', $eout='', undef); # Get our noses rubbed in it foreach my $listen (@listeners) { my $fn = $listen->{fd}->fileno(); # Check if this filedescriptor has data waiting if (vec($rout, $fn, 1)) { # This filedescriptor ($listen) is ready for # reading (or has been closed at the remote # end) } } #### use Time::HiRes qw/time/; # Code will work without this, but works better with my @timers; sub addTimeout { my ($timeout, $callback, $calldata) = @_; push @timers, { when => time()+$timeout, callback => $callback calldata => $calldata }; @timers = sort { $a->{when} <=> $b->{when} } @timers; } #### $now = time(); while ($timers[0]->{when} <= $now) { my $timeout = shift @timers; &{$timeout->{callback}}($timeout->{calldata}); } select($rout=$bits, $wout='', $eout='', $timers[0]->{when}-$now);