--- AnyEvent/lib/AnyEvent.pm 2009/03/26 20:17:44 1.198 +++ AnyEvent/lib/AnyEvent.pm 2009/04/01 15:29:00 1.202 @@ -170,11 +170,17 @@ You can create an I/O watcher by calling the C<< AnyEvent->io >> method with the following mandatory key-value pairs as arguments: -C the Perl I (I file descriptor) to watch for events -(AnyEvent might or might not keep a reference to this file handle). C -must be a string that is either C or C, which creates a watcher -waiting for "r"eadable or "w"ritable events, respectively. C is the -callback to invoke each time the file handle becomes ready. +C is the Perl I (I file descriptor) to watch +for events (AnyEvent might or might not keep a reference to this file +handle). Note that only file handles pointing to things for which +non-blocking operation makes sense are allowed. This includes sockets, +most character devices, pipes, fifos and so on, but not for example files +or block devices. + +C must be a string that is either C or C, which creates a +watcher waiting for "r"eadable or "w"ritable events, respectively. + +C is the callback to invoke each time the file handle becomes ready. Although the callback might get passed parameters, their value and presence is undefined and you cannot rely on them. Portable AnyEvent @@ -869,7 +875,7 @@ use Carp; -our $VERSION = 4.341; +our $VERSION = 4.35; our $MODEL; our $AUTOLOAD; @@ -1066,13 +1072,16 @@ my (undef, %arg) = @_; unless ($SIGPIPE_R) { + require Fcntl; + if (AnyEvent::WIN32) { + require AnyEvent::Util; + ($SIGPIPE_R, $SIGPIPE_W) = AnyEvent::Util::portable_pipe (); AnyEvent::Util::fh_nonblocking ($SIGPIPE_R) if $SIGPIPE_R; AnyEvent::Util::fh_nonblocking ($SIGPIPE_W) if $SIGPIPE_W; # just in case } else { pipe $SIGPIPE_R, $SIGPIPE_W; - require Fcntl; fcntl $SIGPIPE_R, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK if $SIGPIPE_R; fcntl $SIGPIPE_W, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK if $SIGPIPE_W; # just in case } @@ -1080,6 +1089,10 @@ $SIGPIPE_R or Carp::croak "AnyEvent: unable to create a signal reporting pipe: $!\n"; + # not strictly required, as $^F is normally 2, but let's make sure... + fcntl $SIGPIPE_R, &Fcntl::F_SETFD, &Fcntl::FD_CLOEXEC; + fcntl $SIGPIPE_W, &Fcntl::F_SETFD, &Fcntl::FD_CLOEXEC; + $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R, poll => "r", cb => \&_signal_exec); } @@ -1088,6 +1101,7 @@ $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; $SIG{$signal} ||= sub { + local $!; syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV; undef $SIG_EV{$signal}; };