AnyEvent

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

TODO: more formats for parse_ipv6 (single ipv6 address without port, ...p80, ...#80)
TODO: inet_aton maybe pack C4? no, add a comment why not
TODO: socket prepare callbacks, can they easily signal failure as well?
TODO: Олег Г <verdrehung@gmail.com>, empty A record response causes
AnyEvent::resolve_sockaddr to eventually call pack_sockaddr with undef -
broken dns server, but maybe improve the response.

7.17 Wed Sep 18 03:04:49 CEST 2019
	- work around antique openssl version in RHEL 7  by formatting
          dh parameters differently (reported by several people).
	- add t/13_weaken.t.

7.16 Fri Jul 19 18:00:21 CEST 2019
	- add ffdhe group dh parameters from RFC 7919, and use ffdhe3072
          as new default, instead of schmorp1539.
        - AnyEvent::Log did not reassess logging status of
          AnyEvent::Log::logger's when contexts were changed with
          ->attach/detach/slaves, causing them to not log even though a
          recent attach should have caused them to log.
	- added some more logging configuration examples.
        - mention RFC 8482 in AnyEvent::DNS.

MANIFEST  view on Meta::CPAN

t/04_condvar.t
t/05_dns.t
t/06_socket.t
t/07_io.t
t/08_idna.t
t/09_multi.t
t/10_loadall.t
t/io_common
t/11_io_perl.t
t/12_io_ioaio.t
t/13_weaken.t
t/handle/01_readline.t
t/handle/02_write.t
t/handle/03_http_req.t
t/handle/04_listen.t

t/80_ssltest.t
t/81_hosts.t

eg/bench
eg/runbench

lib/AnyEvent/DNS.pm  view on Meta::CPAN

      reuse_q => [],
   }, $class;

   # search should default to gethostname's domain
   # but perl lacks a good posix module

   # try to create an ipv4 and an ipv6 socket
   # only fail when we cannot create either
   my $got_socket;

   Scalar::Util::weaken (my $wself = $self);

   if (socket my $fh4, AF_INET , Socket::SOCK_DGRAM(), 0) {
      ++$got_socket;

      AnyEvent::fh_unblock $fh4;
      $self->{fh4} = $fh4;
      $self->{rw4} = AE::io $fh4, 0, sub {
         if (my $peer = recv $fh4, my $pkt, MAX_PKT, 0) {
            $wself->_recv ($pkt, $peer);
         }

lib/AnyEvent/Debug.pm  view on Meta::CPAN

            cb     => $cb,
            called => 0,
            rt     => \$t,
         }, "AnyEvent::Debug::Wrapped";

         delete $arg{cb};

         $self->{bt} = AnyEvent::Debug::backtrace 1
            if $WRAP_LEVEL >= 2;

         Scalar::Util::weaken ($w = $self);
         Scalar::Util::weaken ($AnyEvent::Debug::Wrapped{Scalar::Util::refaddr $self} = $self);

         $TRACE_LOGGER->("creat $w") if $TRACE_ENABLED && $t;

         $self
      };
   }
}

package AnyEvent::Debug::Wrapped;

lib/AnyEvent/Handle.pm  view on Meta::CPAN


   } elsif ($self->{connect}) {
      require AnyEvent::Socket;

      $self->{peername} = $self->{connect}[0]
         unless exists $self->{peername};

      $self->{_skip_drain_rbuf} = 1;

      {
         Scalar::Util::weaken (my $self = $self);

         $self->{_connect} =
            AnyEvent::Socket::tcp_connect (
               $self->{connect}[0],
               $self->{connect}[1],
               sub {
                  my ($fh, $host, $port, $retry) = @_;

                  delete $self->{_connect}; # no longer needed

lib/AnyEvent/Handle.pm  view on Meta::CPAN

               $self->_error (Errno::ETIMEDOUT);
            }

            # callback could have changed timeout value, optimise
            return unless $self->{$timeout};

            # calculate new after
            $after = $self->{$timeout};
         }

         Scalar::Util::weaken $self;
         return unless $self; # ->error could have destroyed $self

         $self->{$tw} ||= AE::timer $after, 0, sub {
            delete $self->{$tw};
            $cb->($self);
         };
      } else {
         delete $self->{$tw};
      }
   }

lib/AnyEvent/Handle.pm  view on Meta::CPAN

This method may invoke callbacks (and therefore the handle might be
destroyed after it returns).

=cut

sub _drain_wbuf {
   my ($self) = @_;

   if (!$self->{_ww} && length $self->{wbuf}) {

      Scalar::Util::weaken $self;

      my $cb = sub {
         my $len = syswrite $self->{fh}, $self->{wbuf};

         if (defined $len) {
            substr $self->{wbuf}, 0, $len, "";

            $self->{_activity} = $self->{_wactivity} = AE::now;

            $self->{on_drain}($self)

lib/AnyEvent/Handle.pm  view on Meta::CPAN

sub stop_read {
   my ($self) = @_;

   delete $self->{_rw};
}

sub start_read {
   my ($self) = @_;

   unless ($self->{_rw} || $self->{_eof} || !$self->{fh}) {
      Scalar::Util::weaken $self;

      $self->{_rw} = AE::io $self->{fh}, 0, sub {
         my $rbuf = \($self->{tls} ? my $buf : $self->{rbuf});
         my $len = sysread $self->{fh}, $$rbuf, $self->{read_size}, length $$rbuf;

         if ($len > 0) {
            $self->{_activity} = $self->{_ractivity} = AE::now;

            if ($self->{tls}) {
               Net::SSLeay::BIO_write ($self->{_rbio}, $$rbuf);

lib/AnyEvent/Impl/IOAsync.pm  view on Meta::CPAN


   my $id;

   if (my $ival = $arg{interval}) {
      my $ival_cb; $ival_cb = sub {
         $id = $LOOP->enqueue_timer (delay => $ival, code => $ival_cb);
         &$cb;
      };
      $id = $LOOP->enqueue_timer (delay => $arg{after}, code => $ival_cb);

      # we have to weaken afterwards, but when enqueue dies, we have a memleak.
      # still, we do anything for speed...
      Scalar::Util::weaken $ival_cb;

   } else {
      # IO::Async has problems with overloaded objects
      $id = $LOOP->enqueue_timer (delay => $arg{after}, code => sub {
         undef $id; # IO::Async <= 0.43 bug workaround
         &$cb;
      });
   }

   bless \\$id, "AnyEvent::Impl::IOAsync::timer"

lib/AnyEvent/Impl/UV.pm  view on Meta::CPAN

This module provides transparent support for AnyEvent. You don't have to
do anything to make UV work with AnyEvent except by loading UV before
creating the first AnyEvent watcher.

=cut

package AnyEvent::Impl::UV;

use AnyEvent (); BEGIN { AnyEvent::common_sense }
use UV 0.24;
use Scalar::Util qw(weaken);

sub warnlog {
   my $err = UV::last_error;

   AnyEvent::log warn => "returned $_[0]: "
                         . UV::err_name ($err) . "($err): "
                         . UV::strerror ($err);

   @_
}

lib/AnyEvent/Impl/UV.pm  view on Meta::CPAN


   my $master = $io_watchers{$fd} ||= { fd => $fd };

   unless (defined $master->{w}) {
      $master->{w} = UV::poll_init $fd;
      return warnlog $master->{w} unless defined $master->{w};
      $master->{slaves} = {};
   }

   my $slave = AnyEvent::Impl::UV::io_slave->new ($master);
   weaken ($master->{slaves}->{$slave} = $slave);

   $slave->{mode}  = $arg{poll} eq "r" ? UV::READABLE : UV::WRITABLE;
   $master->{mode} = 0 unless defined $master->{mode};
   $slave->{cb}    = $arg{cb};

   unless ($master->{mode} & $slave->{mode}) {
      $master->{mode} |= $slave->{mode};
      my $rc = UV::poll_start $master->{w}, $master->{mode}, sub {
         io_watcher_cb $master->{slaves}, @_;
      };

lib/AnyEvent/Loop.pm  view on Meta::CPAN


Blocks until at least one new event has been received by the operating
system, whether or not it was AnyEvent-related.

=back

=cut

package AnyEvent::Loop;

use Scalar::Util qw(weaken);
use List::Util ();

use AnyEvent (); BEGIN { AnyEvent::common_sense }
use AnyEvent::Util ();

our $VERSION = $AnyEvent::VERSION;

our ($NOW, $MNOW);

sub MAXWAIT() { 3600 } # never sleep for longer than this many seconds

lib/AnyEvent/Loop.pm  view on Meta::CPAN


   my $fds = $fds[$self->[1]];

   # add watcher to fds structure
   my $q = $fds->[W][$fd] ||= [];

   (vec $fds->[V], $fd, 1) = 1;

   $self->[3] = @$q;
   push @$q, $self;
   weaken $q->[-1];

   $self
}

sub AnyEvent::Loop::io::DESTROY {
   my ($self) = @_;

   my $fds = $fds[$self->[1]];

   # remove watcher from fds structure
   my $fd = $self->[0];

   if (@{ $fds->[W][$fd] } == 1) {
      delete $fds->[W][$fd];
      (vec $fds->[V], $fd, 1) = 0;
   } else {
      my $q = $fds->[W][$fd];
      my $last = pop @$q;

      if ($last != $self) {
         weaken ($q->[$self->[3]] = $last);
         $last->[3] = $self->[3];
      }
   }
}

sub timer($$$) {
   my ($after, $interval, $cb) = @_;
   
   my $self;

   if ($interval) {
      $self = [$MNOW + $after , sub {
         $_[0][0] = List::Util::max $_[0][0] + $interval, $MNOW;
         push @timer, $_[0];
         weaken $timer[-1];
         $need_sort = $_[0][0] if $_[0][0] < $need_sort;
         &$cb;
      }];
   } else {
      $self = [$MNOW + $after, $cb];
   }

   push @timer, $self;
   weaken $timer[-1];
   $need_sort = $self->[0] if $self->[0] < $need_sort;

   $self
}

sub idle($) {
   my $cb = shift;

   push @idle, \\$cb;
   weaken ${$idle[-1]};

   ${$idle[-1]}
}

=head1 SEE ALSO

L<AnyEvent>.

=head1 AUTHOR

lib/AnyEvent/TLS.pm  view on Meta::CPAN

      Net::SSLeay::set_connect_state ($session);

      Net::SSLeay::set_options ($session, eval { Net::SSLeay::OP_NO_TICKET () })
         unless $self->{session_ticket};
   } else {
      croak "'$mode': unsupported TLS mode (must be either 'connect' or 'accept')"
   }

#   # associate data
#   Net::SSLeay::set_ex_data ($session, $REF_IDX, $ref+0);
#   Scalar::Util::weaken ($REF_MAP{$ref+0} = $ref)
#      if ref $ref;
   
   if ($self->{debug}) {
      #d# Net::SSLeay::set_info_callback ($session, 50000);
   }

   if ($self->{verify_mode}) {
      Scalar::Util::weaken $self;
      Scalar::Util::weaken $ref;

      # we have to provide a dummy callbacks as at least Net::SSLeay <= 1.35
      # try to call it even if specified as 0 or undef.
      Net::SSLeay::set_verify
         $session,
         $self->{verify_mode},
         sub { $self->verify ($session, $ref, $cn, @_) };
   }

   $session

t/13_weaken.t  view on Meta::CPAN

use Scalar::Util qw(weaken);
use AnyEvent;
BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} }

$| = 1; print "1..7\n";

print "ok 1\n";

my $c1 = AnyEvent->condvar;
my $c2 = AE::cv;

my $t1 = AnyEvent->timer (after => 0.1, cb => sub { print "ok 3\n"; $c1->() });
my $t2 = AnyEvent->timer (after => 0.5, cb => sub { print "not ok 6\n" });
my $t3 = AnyEvent->timer (after => 0.9, cb => sub { print "ok 6\n"; $c2->send });

print "ok 2\n";

$c1->wait;

print "ok 4\n";

Scalar::Util::weaken $t2;

print $t2 ? "not " : "", "ok 5\n";

$c2->wait;

print "ok 7\n";



( run in 0.328 second using v1.01-cache-2.11-cpan-65fba6d93b7 )