r44254 - in /branches/upstream/libanyevent-perl/current: Changes META.yml README lib/AnyEvent.pm lib/AnyEvent/Handle.pm lib/AnyEvent/Impl/Perl.pm

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Sat Sep 19 02:59:34 UTC 2009


Author: jawnsy-guest
Date: Sat Sep 19 02:59:23 2009
New Revision: 44254

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=44254
Log:
[svn-upgrade] Integrating new upstream version, libanyevent-perl (5.200)

Modified:
    branches/upstream/libanyevent-perl/current/Changes
    branches/upstream/libanyevent-perl/current/META.yml
    branches/upstream/libanyevent-perl/current/README
    branches/upstream/libanyevent-perl/current/lib/AnyEvent.pm
    branches/upstream/libanyevent-perl/current/lib/AnyEvent/Handle.pm
    branches/upstream/libanyevent-perl/current/lib/AnyEvent/Impl/Perl.pm

Modified: branches/upstream/libanyevent-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libanyevent-perl/current/Changes?rev=44254&op=diff
==============================================================================
--- branches/upstream/libanyevent-perl/current/Changes (original)
+++ branches/upstream/libanyevent-perl/current/Changes Sat Sep 19 02:59:23 2009
@@ -1,4 +1,15 @@
 Revision history for Perl extension AnyEvent.
+
+5.2  Mon Sep 14 07:04:49 CEST 2009
+	- INCOMPATIBLE CHANGE: do no longer support register_read_type
+          and register_write_type in AnyEvent::Handle, instead support
+          package names (the facility was mostly abused).
+        - implement "packagename-as-read/write type" support in
+          AnyEvent::Handle.
+	- AnyEvent::Handle: new options "keepalive" and "oobinline".
+        - oobinline set by default to avoid security issues.
+        - the pure-perl event loop backend wrongly detected times() fallback
+          support (spotted by Pavel Boldin).
 
 5.12 Tue Sep  1 20:26:50 CEST 2009
 	- be more lenient when parsing resolv.conf files, as some people

Modified: branches/upstream/libanyevent-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libanyevent-perl/current/META.yml?rev=44254&op=diff
==============================================================================
--- branches/upstream/libanyevent-perl/current/META.yml (original)
+++ branches/upstream/libanyevent-perl/current/META.yml Sat Sep 19 02:59:23 2009
@@ -11,7 +11,7 @@
    },
    "generated_by" : "ExtUtils::MakeMaker version 6.50",
    "distribution_type" : "module",
-   "version" : "5.12",
+   "version" : "5.2",
    "name" : "AnyEvent",
    "author" : [],
    "license" : "unknown",

Modified: branches/upstream/libanyevent-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libanyevent-perl/current/README?rev=44254&op=diff
==============================================================================
--- branches/upstream/libanyevent-perl/current/README (original)
+++ branches/upstream/libanyevent-perl/current/README Sat Sep 19 02:59:23 2009
@@ -1744,9 +1744,9 @@
         operation much. It is purely used for performance.
 
     JSON and JSON::XS
-        This module is required when you want to read or write JSON data via
-        AnyEvent::Handle. It is also written in pure-perl, but can take
-        advantage of the ultra-high-speed JSON::XS module when it is
+        One of these modules is required when you want to read or write JSON
+        data via AnyEvent::Handle. It is also written in pure-perl, but can
+        take advantage of the ultra-high-speed JSON::XS module when it is
         installed.
 
         In fact, AnyEvent::Handle will use JSON::XS by default if it is

Modified: branches/upstream/libanyevent-perl/current/lib/AnyEvent.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libanyevent-perl/current/lib/AnyEvent.pm?rev=44254&op=diff
==============================================================================
--- branches/upstream/libanyevent-perl/current/lib/AnyEvent.pm (original)
+++ branches/upstream/libanyevent-perl/current/lib/AnyEvent.pm Sat Sep 19 02:59:23 2009
@@ -1118,7 +1118,7 @@
 
 use Carp ();
 
-our $VERSION = '5.12';
+our $VERSION = '5.2';
 our $MODEL;
 
 our $AUTOLOAD;
@@ -2475,8 +2475,8 @@
 
 =item L<JSON> and L<JSON::XS>
 
-This module is required when you want to read or write JSON data via
-L<AnyEvent::Handle>. It is also written in pure-perl, but can take
+One of these modules is required when you want to read or write JSON data
+via L<AnyEvent::Handle>. It is also written in pure-perl, but can take
 advantage of the ultra-high-speed L<JSON::XS> module when it is installed.
 
 In fact, L<AnyEvent::Handle> will use L<JSON::XS> by default if it is

Modified: branches/upstream/libanyevent-perl/current/lib/AnyEvent/Handle.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libanyevent-perl/current/lib/AnyEvent/Handle.pm?rev=44254&op=diff
==============================================================================
--- branches/upstream/libanyevent-perl/current/lib/AnyEvent/Handle.pm (original)
+++ branches/upstream/libanyevent-perl/current/lib/AnyEvent/Handle.pm Sat Sep 19 02:59:23 2009
@@ -62,6 +62,21 @@
 
 our $VERSION = $AnyEvent::VERSION;
 
+sub _load_func($) {
+   my $func = $_[0];
+
+   unless (defined &$func) {
+      my $pkg = $func;
+      do {
+         $pkg =~ s/::[^:]+$//
+            or return;
+         eval "require $pkg";
+      } until defined &$func;
+   }
+
+   \&$func
+}
+
 =head1 METHODS
 
 =over 4
@@ -116,16 +131,17 @@
 parameters, together with a retry callback.
 
 When, for some reason, the handle is not acceptable, then calling
-C<$retry> will continue with the next conenction target (in case of
+C<$retry> will continue with the next connection target (in case of
 multi-homed hosts or SRV records there can be multiple connection
-endpoints). When it is called then the read and write queues, eof status,
-tls status and similar properties of the handle are being reset.
+endpoints). At the time it is called the read and write queues, eof
+status, tls status and similar properties of the handle will have been
+reset.
 
 In most cases, ignoring the C<$retry> parameter is the way to go.
 
 =item on_connect_error => $cb->($handle, $message)
 
-This callback is called when the conenction could not be
+This callback is called when the connection could not be
 established. C<$!> will contain the relevant error code, and C<$message> a
 message describing it (usually the same as C<"$!">).
 
@@ -287,6 +303,38 @@
 The default is your opertaing system's default behaviour (most likely
 enabled), this option explicitly enables or disables it, if possible.
 
+=item keepalive => <boolean>
+
+Enables (default disable) the SO_KEEPALIVE option on the stream socket:
+normally, TCP connections have no time-out once established, so TCP
+connections, once established, can stay alive forever even when the other
+side has long gone. TCP keepalives are a cheap way to take down long-lived
+TCP connections whent he other side becomes unreachable. While the default
+is OS-dependent, TCP keepalives usually kick in after around two hours,
+and, if the other side doesn't reply, take down the TCP connection some 10
+to 15 minutes later.
+
+It is harmless to specify this option for file handles that do not support
+keepalives, and enabling it on connections that are potentially long-lived
+is usually a good idea.
+
+=item oobinline => <boolean>
+
+BSD majorly fucked up the implementation of TCP urgent data. The result
+is that almost no OS implements TCP according to the specs, and every OS
+implements it slightly differently.
+
+If you want to handle TCP urgent data, then setting this flag (the default
+is enabled) gives you the most portable way of getting urgent data, by
+putting it into the stream.
+
+Since BSD emulation of OOB data on top of TCP's urgent data can have
+security implications, AnyEvent::Handle sets this flag automatically
+unless explicitly specified. Note that setting this flag after
+establishing a connection I<may> be a bit too late (data loss could
+already have occured on BSD systems), but at least it will protect you
+from most attacks.
+
 =item read_size => <bytes>
 
 The default read block size (the amount of bytes this module will
@@ -329,7 +377,7 @@
 =item tls => "accept" | "connect" | Net::SSLeay::SSL object
 
 When this parameter is given, it enables TLS (SSL) mode, that means
-AnyEvent will start a TLS handshake as soon as the conenction has been
+AnyEvent will start a TLS handshake as soon as the connection has been
 established and will transparently encrypt/decrypt data afterwards.
 
 All TLS protocol errors will be signalled as C<EPROTO>, with an
@@ -492,16 +540,19 @@
    $self->{_ractivity} =
    $self->{_wactivity} = AE::now;
 
-   $self->timeout  (delete $self->{timeout} ) if $self->{timeout};
-   $self->rtimeout (delete $self->{rtimeout}) if $self->{rtimeout};
-   $self->wtimeout (delete $self->{wtimeout}) if $self->{wtimeout};
-
-   $self->no_delay (delete $self->{no_delay}) if exists $self->{no_delay};
-
-   $self->starttls (delete $self->{tls}, delete $self->{tls_ctx})
+   $self->timeout   (delete $self->{timeout}  ) if $self->{timeout};
+   $self->rtimeout  (delete $self->{rtimeout} ) if $self->{rtimeout};
+   $self->wtimeout  (delete $self->{wtimeout} ) if $self->{wtimeout};
+
+   $self->no_delay  (delete $self->{no_delay} ) if exists $self->{no_delay}  && $self->{no_delay};
+   $self->keepalive (delete $self->{keepalive}) if exists $self->{keepalive} && $self->{keepalive};
+
+   $self->oobinline (exists $self->{oobinline} ? delete $self->{oobinline} : 1);
+
+   $self->starttls  (delete $self->{tls}, delete $self->{tls_ctx})
       if $self->{tls};
 
-   $self->on_drain (delete $self->{on_drain}) if $self->{on_drain};
+   $self->on_drain  (delete $self->{on_drain}) if $self->{on_drain};
 
    $self->start_read
       if $self->{on_read} || @{ $self->{_queue} };
@@ -518,7 +569,7 @@
    if ($self->{on_error}) {
       $self->{on_error}($self, $fatal, $message);
       $self->destroy if $fatal;
-   } elsif ($self->{fh}) {
+   } elsif ($self->{fh} || $self->{connect}) {
       $self->destroy;
       Carp::croak "AnyEvent::Handle uncaught error: $message";
    }
@@ -589,7 +640,58 @@
 
    eval {
       local $SIG{__DIE__};
-      setsockopt $_[0]{fh}, &Socket::IPPROTO_TCP, &Socket::TCP_NODELAY, int $_[1]
+      setsockopt $_[0]{fh}, Socket::IPPROTO_TCP (), Socket::TCP_NODELAY (), int $_[1]
+         if $_[0]{fh};
+   };
+}
+
+=item $handle->keepalive ($boolean)
+
+Enables or disables the C<keepalive> setting (see constructor argument of
+the same name for details).
+
+=cut
+
+sub keepalive {
+   $_[0]{keepalive} = $_[1];
+
+   eval {
+      local $SIG{__DIE__};
+      setsockopt $_[0]{fh}, Socket::SOL_SOCKET (), Socket::SO_KEEPALIVE (), int $_[1]
+         if $_[0]{fh};
+   };
+}
+
+=item $handle->oobinline ($boolean)
+
+Enables or disables the C<oobinline> setting (see constructor argument of
+the same name for details).
+
+=cut
+
+sub oobinline {
+   $_[0]{oobinline} = $_[1];
+
+   eval {
+      local $SIG{__DIE__};
+      setsockopt $_[0]{fh}, Socket::SOL_SOCKET (), Socket::SO_OOBINLINE (), int $_[1]
+         if $_[0]{fh};
+   };
+}
+
+=item $handle->keepalive ($boolean)
+
+Enables or disables the C<keepalive> setting (see constructor argument of
+the same name for details).
+
+=cut
+
+sub keepalive {
+   $_[0]{keepalive} = $_[1];
+
+   eval {
+      local $SIG{__DIE__};
+      setsockopt $_[0]{fh}, Socket::SOL_SOCKET (), Socket::SO_KEEPALIVE (), int $_[1]
          if $_[0]{fh};
    };
 }
@@ -787,6 +889,7 @@
 
 our %WH;
 
+# deprecated
 sub register_write_type($$) {
    $WH{$_[0]} = $_[1];
 }
@@ -797,7 +900,8 @@
    if (@_ > 1) {
       my $type = shift;
 
-      @_ = ($WH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_write")
+      @_ = ($WH{$type} ||= _load_func "$type\::anyevent_write_type"
+            or Carp::croak "unsupported/unloadable type '$type' passed to AnyEvent::Handle::push_write")
            ->($self, @_);
    }
 
@@ -812,8 +916,11 @@
 
 =item $handle->push_write (type => @args)
 
-Instead of formatting your data yourself, you can also let this module do
-the job by specifying a type and type-specific arguments.
+Instead of formatting your data yourself, you can also let this module
+do the job by specifying a type and type-specific arguments. You
+can also specify the (fully qualified) name of a package, in which
+case AnyEvent tries to load the package and then expects to find the
+C<anyevent_read_type> function inside (see "custom write types", below).
 
 Predefined types are (if you have ideas for additional types, feel free to
 drop by and tell us):
@@ -935,17 +1042,37 @@
    $self->on_drain (sub { shutdown $_[0]{fh}, 1 });
 }
 
-=item AnyEvent::Handle::register_write_type type => $coderef->($handle, @args)
-
-This function (not method) lets you add your own types to C<push_write>.
-Whenever the given C<type> is used, C<push_write> will invoke the code
-reference with the handle object and the remaining arguments.
-
-The code reference is supposed to return a single octet string that will
-be appended to the write buffer.
-
-Note that this is a function, and all types registered this way will be
-global, so try to use unique names.
+=item custom write types - Package::anyevent_write_type $handle, @args
+
+Instead of one of the predefined types, you can also specify the name of
+a package. AnyEvent will try to load the package and then expects to find
+a function named C<anyevent_write_type> inside. If it isn't found, it
+progressively tries to load the parent package until it either finds the
+function (good) or runs out of packages (bad).
+
+Whenever the given C<type> is used, C<push_write> will the function with
+the handle object and the remaining arguments.
+
+The function is supposed to return a single octet string that will be
+appended to the write buffer, so you cna mentally treat this function as a
+"arguments to on-the-wire-format" converter.
+
+Example: implement a custom write type C<join> that joins the remaining
+arguments using the first one.
+
+   $handle->push_write (My::Type => " ", 1,2,3);
+
+   # uses the following package, which can be defined in the "My::Type" or in
+   # the "My" modules to be auto-loaded, or just about anywhere when the
+   # My::Type::anyevent_write_type is defined before invoking it.
+
+   package My::Type;
+
+   sub anyevent_write_type {
+      my ($handle, $delim, @args) = @_;
+
+      join $delim, @args
+   }
 
 =cut
 
@@ -1174,7 +1301,8 @@
    if (@_) {
       my $type = shift;
 
-      $cb = ($RH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_read")
+      $cb = ($RH{$type} ||= _load_func "$type\::anyevent_read_type"
+             or Carp::croak "unsupported/unloadable type '$type' passed to AnyEvent::Handle::push_read")
             ->($self, $cb, @_);
    }
 
@@ -1203,7 +1331,9 @@
 
 Instead of providing a callback that parses the data itself you can chose
 between a number of predefined parsing formats, for chunks of data, lines
-etc.
+etc. You can also specify the (fully qualified) name of a package, in
+which case AnyEvent tries to load the package and then expects to find the
+C<anyevent_read_type> function inside (see "custom read types", below).
 
 Predefined types are (if you have ideas for additional types, feel free to
 drop by and tell us):
@@ -1532,25 +1662,28 @@
 
 =back
 
-=item AnyEvent::Handle::register_read_type type => $coderef->($handle, $cb, @args)
-
-This function (not method) lets you add your own types to C<push_read>.
-
-Whenever the given C<type> is used, C<push_read> will invoke the code
-reference with the handle object, the callback and the remaining
-arguments.
-
-The code reference is supposed to return a callback (usually a closure)
-that works as a plain read callback (see C<< ->push_read ($cb) >>).
-
-It should invoke the passed callback when it is done reading (remember to
-pass C<$handle> as first argument as all other callbacks do that).
-
-Note that this is a function, and all types registered this way will be
-global, so try to use unique names.
-
-For examples, see the source of this module (F<perldoc -m AnyEvent::Handle>,
-search for C<register_read_type>)).
+=item custom read types - Package::anyevent_read_type $handle, $cb, @args
+
+Instead of one of the predefined types, you can also specify the name
+of a package. AnyEvent will try to load the package and then expects to
+find a function named C<anyevent_read_type> inside. If it isn't found, it
+progressively tries to load the parent package until it either finds the
+function (good) or runs out of packages (bad).
+
+Whenever this type is used, C<push_read> will invoke the function with the
+handle object, the original callback and the remaining arguments.
+
+The function is supposed to return a callback (usually a closure) that
+works as a plain read callback (see C<< ->push_read ($cb) >>), so you can
+mentally treat the function as a "configurable read type to read callback"
+converter.
+
+It should invoke the original callback when it is done reading (remember
+to pass C<$handle> as first argument as all other callbacks do that,
+although there is no strict requirement on this).
+
+For examples, see the source of this module (F<perldoc -m
+AnyEvent::Handle>, search for C<register_read_type>)).
 
 =item $handle->stop_read
 

Modified: branches/upstream/libanyevent-perl/current/lib/AnyEvent/Impl/Perl.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libanyevent-perl/current/lib/AnyEvent/Impl/Perl.pm?rev=44254&op=diff
==============================================================================
--- branches/upstream/libanyevent-perl/current/lib/AnyEvent/Impl/Perl.pm (original)
+++ branches/upstream/libanyevent-perl/current/lib/AnyEvent/Impl/Perl.pm Sat Sep 19 02:59:23 2009
@@ -119,17 +119,17 @@
 BEGIN {
    local $SIG{__DIE__};
    my $time_hires = eval "use Time::HiRes (); 1";
-   my $clk_tck    = eval "use POSIX (); POSIX::sysconf (&POSIX::_SC_CLK_TCK)";
+   my $clk_tck    = eval "use POSIX (); POSIX::sysconf (POSIX::_SC_CLK_TCK ())";
    my $round; # actual granularity
 
-   if ($time_hires && eval "&Time::HiRes::clock_gettime (&Time::HiRes::CLOCK_MONOTONIC)") {
+   if ($time_hires && eval "&Time::HiRes::clock_gettime (Time::HiRes::CLOCK_MONOTONIC ())") {
       warn "AnyEvent::Impl::Perl: using CLOCK_MONOTONIC as timebase.\n" if $AnyEvent::VERBOSE >= 8;
       *_update_clock = sub {
          $NOW  = &Time::HiRes::time;
          $MNOW = Time::HiRes::clock_gettime (&Time::HiRes::CLOCK_MONOTONIC);
       };
 
-   } elsif (100 <= $clk_tck && $clk_tck <= 1000000 && "use POSIX (); (POSIX::times())[0] != -1") { # -1 is also a valid return value :/
+   } elsif (100 <= $clk_tck && $clk_tck <= 1000000 && eval { (POSIX::times ())[0] != -1 }) { # -1 is also a valid return value :/
       warn "AnyEvent::Impl::Perl: using POSIX::times (monotonic) as timebase.\n" if $AnyEvent::VERBOSE >= 8;
       my $HZ1 = 1 / $clk_tck;
 




More information about the Pkg-perl-cvs-commits mailing list