--- EV/EV.pm 2008/05/26 05:37:18 1.97 +++ EV/EV.pm 2008/05/31 23:17:50 1.98 @@ -4,54 +4,54 @@ =head1 SYNOPSIS - use EV; - - # TIMERS - - my $w = EV::timer 2, 0, sub { - warn "is called after 2s"; - }; - - my $w = EV::timer 2, 2, sub { - warn "is called roughly every 2s (repeat = 2)"; - }; - - undef $w; # destroy event watcher again - - my $w = EV::periodic 0, 60, 0, sub { - warn "is called every minute, on the minute, exactly"; - }; - - # IO - - my $w = EV::io *STDIN, EV::READ, sub { - my ($w, $revents) = @_; # all callbacks receive the watcher and event mask - warn "stdin is readable, you entered: ", ; - }; - - # SIGNALS - - my $w = EV::signal 'QUIT', sub { - warn "sigquit received\n"; - }; + use EV; + + # TIMERS + + my $w = EV::timer 2, 0, sub { + warn "is called after 2s"; + }; + + my $w = EV::timer 2, 2, sub { + warn "is called roughly every 2s (repeat = 2)"; + }; + + undef $w; # destroy event watcher again + + my $w = EV::periodic 0, 60, 0, sub { + warn "is called every minute, on the minute, exactly"; + }; + + # IO + + my $w = EV::io *STDIN, EV::READ, sub { + my ($w, $revents) = @_; # all callbacks receive the watcher and event mask + warn "stdin is readable, you entered: ", ; + }; + + # SIGNALS + + my $w = EV::signal 'QUIT', sub { + warn "sigquit received\n"; + }; + + # CHILD/PID STATUS CHANGES - # CHILD/PID STATUS CHANGES - - my $w = EV::child 666, 0, sub { - my ($w, $revents) = @_; - my $status = $w->rstatus; - }; - - # STAT CHANGES - my $w = EV::stat "/etc/passwd", 10, sub { - my ($w, $revents) = @_; - warn $w->path, " has changed somehow.\n"; - }; + my $w = EV::child 666, 0, sub { + my ($w, $revents) = @_; + my $status = $w->rstatus; + }; - # MAINLOOP - EV::loop; # loop until EV::unloop is called or all watchers stop - EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled - EV::loop EV::LOOP_NONBLOCK; # try to handle same events, but do not block + # STAT CHANGES + my $w = EV::stat "/etc/passwd", 10, sub { + my ($w, $revents) = @_; + warn $w->path, " has changed somehow.\n"; + }; + + # MAINLOOP + EV::loop; # loop until EV::unloop is called or all watchers stop + EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled + EV::loop EV::LOOP_NONBLOCK; # try to handle same events, but do not block =head1 DESCRIPTION @@ -285,10 +285,10 @@ event. For instance, if you want to wait for STDIN to become readable, you would create an EV::io watcher for that: - my $watcher = EV::io *STDIN, EV::READ, sub { - my ($watcher, $revents) = @_; - warn "yeah, STDIN should now be readable without blocking!\n" - }; + my $watcher = EV::io *STDIN, EV::READ, sub { + my ($watcher, $revents) = @_; + warn "yeah, STDIN should now be readable without blocking!\n" + }; All watchers can be active (waiting for events) or inactive (paused). Only active watchers will have their callbacks invoked. All callbacks will be @@ -411,7 +411,7 @@ my $udp_socket = ... my $udp_watcher = EV::io $udp_socket, EV::READ, sub { ... }; - $1000udp_watcher->keepalive (0); + $udp_watcher->keepalive (0); =item $loop = $w->loop @@ -953,19 +953,19 @@ In short, this watcher is most useful on BSD systems without working kqueue to still be able to handle a large number of sockets: - my $socket_loop; - - # check wether we use SELECT or POLL _and_ KQUEUE is supported - if ( - (EV::backend & (EV::BACKEND_POLL | EV::BACKEND_SELECT)) - && (EV::supported_backends & EV::embeddable_backends & EV::BACKEND_KQUEUE) - ) { - # use kqueue for sockets - $socket_loop = new EV::Loop EV::BACKEND_KQUEUE | EV::FLAG_NOENV; - } - - # use the default loop otherwise - $socket_loop ||= EV::default_loop; + my $socket_loop; + + # check wether we use SELECT or POLL _and_ KQUEUE is supported + if ( + (EV::backend & (EV::BACKEND_POLL | EV::BACKEND_SELECT)) + && (EV::supported_backends & EV::embeddable_backends & EV::BACKEND_KQUEUE) + ) { + # use kqueue for sockets + $socket_loop = new EV::Loop EV::BACKEND_KQUEUE | EV::FLAG_NOENV; + } + + # use the default loop otherwise + $socket_loop ||= EV::default_loop; =over 4 @@ -1071,8 +1071,8 @@ =head1 AUTHOR - Marc Lehmann - http://home.schmorp.de/ + Marc Lehmann + http://home.schmorp.de/ =cut