Commit 800e22c3 authored by gregor herrmann's avatar gregor herrmann

Imported Upstream version 7.110

parent 46b98e97
......@@ -8,6 +8,56 @@ TODO: FAQ: scope-ids? hosts file order?
TODO: AnyEvent::Handle with AnyEvent::IO?
TODO: invalid. and localhost. specialcasing inside AEDNS and not AESocket (rfc6761)
TODO: maybe implement env variable to give hosts precedence
TODO: hosts always read? that's not expected
TODO: more formats for parse_ipv6 (single ipv6 address without port, ...p80, ...#80)
7.11 Thu Jul 16 14:36:00 CEST 2015
- AnyEvent::Socket::parse_ipv6 could accept malformed ipv6
addresses (extra "::" at end and similar cases).
- add a more explicit warning to AnyEvent::Handle that it doesn't
work on files, people keep getting confused.
- new function AnyEvent::Socket::tcp_bind.
- new functions AnyEvent::fh_block and AnyEvent::fh_unblock.
- aligned ipv6 address formatting with RFC 5952 (by not shortening
a single :0: to ::).
- added stability canary support.
7.09 Sat May 2 16:38:53 CEST 2015
- AnyEvent::Debug called an internal function (AnyEvent::Log::ft)
that was renamed to AnyEvent::Log:format_time. uinder its old name
(analyzed by Michael Stovenour).
- update AnyEvent::DNS fallback resolver addresses:
seems google effectively killed most other free dns resolvers,
so remove them, but add cable and wireless (ecrc) since it was
stable for 20 years or so, official or not, and there should be
an alternative to google.
- perl5porters broke windows error codes in 5.20, and mapped
WSAEWOULDBLOCK on the (different) EWOULDBLOCK error code, and
WSAEINPROGRESS into the incompatible ERINPROGRESS code, probably
because they were so cool. They probably broke other error codes
for no reason, too, but I didn't care for checking, it's too
depressing. This version only works around the WSAEWOULDBLOCK
issue, because I don't have a nice way to work around the
WSAEINPROGRESS bug.
7.08 Wed Dec 10 05:27:17 CET 2014
- work around a newly introduced bug in Socket 2.011 (an
errornous sun_length check) (analyzed by Maxime Soulé).
- AnyEvent::TLS didn't load (but refer to) AnyEvent::Socket
(analyzed by Ben Magistro).
- AnyEvent::Strict will now confess, not croak. This is in line with
it being a development/debugging tool.
- work around a number of libglib bugs (debug builds of libglib enforce
certain undocumented behaviour patterns such as not being able to
remove a child watch source after it has fired, which we will try
to emulate to avoid "criticals". what where they thinking...).
- mention json security issues in AnyEvent::Handle, now that Douglas
Crockford has foolishly and incompatibly changed JSON.
- changed default dns resolver "max_outstanding" value from 1 to 10,
the latter beinfg the intended value all along
(reported by Ilya Chesnokov).
- added new "AnyEvent::Impl::UV" interface module to the UV event lib
(written by Mike Lowell).
7.07 Tue Dec 17 17:45:02 CET 2013
- the documentation for custom tls verify schemes was wrong. make it agree
......@@ -630,7 +680,7 @@ TODO: maybe implement env variable to give hosts precedence
- add an additional error message parameter to AnyEvent::Handle's
on_error callback (for TLS, $! is still available).
- add AnyEvent::Handle on_starttls/on_stoptls callbacks.
- make AnyEvent::Handle more robust against early conenction
- make AnyEvent::Handle more robust against early connection
failures (during new), and return C<undef> in that case
from the constructor.
- AnyEvent::Handle will now try to load only JSON::XS first,
......
......@@ -23,6 +23,7 @@ lib/AnyEvent/Impl/POE.pm
lib/AnyEvent/Impl/Perl.pm
lib/AnyEvent/Impl/Qt.pm
lib/AnyEvent/Impl/Tk.pm
lib/AnyEvent/Impl/UV.pm
lib/AnyEvent/IO.pm
lib/AnyEvent/IO/IOAIO.pm
lib/AnyEvent/IO/Perl.pm
......@@ -128,5 +129,13 @@ t/69_ev_04_condvar.t
t/69_ev_05_dns.t
t/69_ev_07_io.t
t/69_ev_09_multi.t
t/70_uv_01_basic.t
t/70_uv_02_signals.t
t/70_uv_03_child.t
t/70_uv_04_condvar.t
t/70_uv_05_dns.t
t/70_uv_07_io.t
t/70_uv_09_multi.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
......@@ -4,7 +4,7 @@
"unknown"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.120921",
"generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001",
"license" : [
"unknown"
],
......@@ -27,7 +27,8 @@
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
"Canary::Stability" : "0",
"ExtUtils::MakeMaker" : "6.52"
}
},
"runtime" : {
......@@ -44,5 +45,5 @@
}
},
"release_status" : "stable",
"version" : "7.07"
"version" : 7.11
}
......@@ -3,27 +3,28 @@ abstract: unknown
author:
- unknown
build_requires:
ExtUtils::MakeMaker: 0
ExtUtils::MakeMaker: '0'
configure_requires:
ExtUtils::MakeMaker: 0
Canary::Stability: '0'
ExtUtils::MakeMaker: '6.52'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.120921'
generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
version: '1.4'
name: AnyEvent
no_index:
directory:
- t
- inc
recommends:
Async::Interrupt: 1
EV: 4
Guard: 1.02
JSON: 2.09
JSON::XS: 2.2
Net::SSLeay: 1.33
Task::Weaken: 0
Async::Interrupt: '1'
EV: '4'
Guard: '1.02'
JSON: '2.09'
JSON::XS: '2.2'
Net::SSLeay: '1.33'
Task::Weaken: '0'
requires: {}
version: 7.07
version: 7.11
use ExtUtils::MakeMaker;
use 5.008001; # AnyEvent perl event loop seems to work with 5.6, other modules not
# AnyEvent perl event loop seems to work with 5.6, other modules not
eval 'use Canary::Stability AnyEvent => 1, 5.008001';
print <<EOF;
......@@ -37,6 +38,7 @@ WriteMakefile(
# PREREQ_PM => {
# Task::Weaken => 0,
# },
CONFIGURE_REQUIRES => { "ExtUtils::MakeMaker" => 6.52, "Canary::Stability" => 0 },
META_MERGE => {
recommends => {
"Task::Weaken" => 0,
......@@ -67,6 +69,7 @@ WriteMakefile(
'lib/AnyEvent/Impl/Perl.pm' => '$(INST_LIB)/AnyEvent/Impl/Perl.pm',
'lib/AnyEvent/Impl/Qt.pm' => '$(INST_LIB)/AnyEvent/Impl/Qt.pm',
'lib/AnyEvent/Impl/Tk.pm' => '$(INST_LIB)/AnyEvent/Impl/Tk.pm',
'lib/AnyEvent/Impl/UV.pm' => '$(INST_LIB)/AnyEvent/Impl/UV.pm',
'lib/AnyEvent/IO.pm' => '$(INST_LIB)/AnyEvent/IO.pm',
'lib/AnyEvent/IO/IOAIO.pm' => '$(INST_LIB)/AnyEvent/IO/IOAIO.pm',
'lib/AnyEvent/IO/Perl.pm' => '$(INST_LIB)/AnyEvent/IO/Perl.pm',
......
NAME
AnyEvent - the DBI of event loop programming
EV, Event, Glib, Tk, Perl, Event::Lib, Irssi, rxvt-unicode, IO::Async,
Qt, FLTK and POE are various supported event loops/environments.
EV, Event, Glib, Tk, UV, Perl, Event::Lib, Irssi, rxvt-unicode,
IO::Async, Qt, FLTK and POE are various supported event
loops/environments.
SYNOPSIS
use AnyEvent;
......@@ -845,6 +846,7 @@ SUPPORTED EVENT LOOPS/BACKENDS
AnyEvent::Impl::Event based on Event, very stable, few glitches.
AnyEvent::Impl::Glib based on Glib, slow but very stable.
AnyEvent::Impl::Tk based on Tk, very broken.
AnyEvent::Impl::UV based on UV, innovated square wheels.
AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse.
AnyEvent::Impl::POE based on POE, very slow, some limitations.
AnyEvent::Impl::Irssi used when running within irssi.
......@@ -986,7 +988,7 @@ GLOBAL VARIABLES AND FUNCTIONS
transaction object or guard to let you cancel the operation. For
example, "AnyEvent::Socket::tcp_connect":
# start a conenction attempt unless one is active
# start a connection attempt unless one is active
$self->{connect_guard} ||= AnyEvent::Socket::tcp_connect "www.example.net", 80, sub {
delete $self->{connect_guard};
...
......@@ -1030,6 +1032,10 @@ GLOBAL VARIABLES AND FUNCTIONS
function, which can reduce typing, codesize and can reduce the
logging overhead enourmously.
AnyEvent::fh_block $filehandle
AnyEvent::fh_unblock $filehandle
Sets blocking or non-blocking behaviour for the given filehandle.
WHAT TO DO IN A MODULE
As a module author, you should "use AnyEvent" and call AnyEvent methods
freely, but you should not load a specific event module or rely on it.
......@@ -1360,7 +1366,7 @@ ENVIRONMENT VARIABLES
This variable can effectively be used for denial-of-service attacks
against local programs (e.g. when setuid), although the impact is
likely small, as the program has to handle conenction and other
likely small, as the program has to handle connection and other
failures anyways.
Examples: "PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6" - prefer IPv4 over
......@@ -2121,12 +2127,13 @@ SEE ALSO
AnyEvent::Debug (interactive shell, watcher tracing).
Supported event modules: AnyEvent::Loop, EV, EV::Glib, Glib::EV, Event,
Glib::Event, Glib, Tk, Event::Lib, Qt, POE, FLTK.
Glib::Event, Glib, Tk, Event::Lib, Qt, POE, FLTK, Cocoa::EventLoop, UV.
Implementations: AnyEvent::Impl::EV, AnyEvent::Impl::Event,
AnyEvent::Impl::Glib, AnyEvent::Impl::Tk, AnyEvent::Impl::Perl,
AnyEvent::Impl::EventLib, AnyEvent::Impl::Qt, AnyEvent::Impl::POE,
AnyEvent::Impl::IOAsync, Anyevent::Impl::Irssi, AnyEvent::Impl::FLTK.
AnyEvent::Impl::IOAsync, AnyEvent::Impl::Irssi, AnyEvent::Impl::FLTK,
AnyEvent::Impl::Cocoa, AnyEvent::Impl::UV.
Non-blocking handles, pipes, stream sockets, TCP clients and servers:
AnyEvent::Handle, AnyEvent::Socket, AnyEvent::TLS.
......
......@@ -2,8 +2,8 @@
AnyEvent - the DBI of event loop programming
EV, Event, Glib, Tk, Perl, Event::Lib, Irssi, rxvt-unicode, IO::Async, Qt,
FLTK and POE are various supported event loops/environments.
EV, Event, Glib, Tk, UV, Perl, Event::Lib, Irssi, rxvt-unicode, IO::Async,
Qt, FLTK and POE are various supported event loops/environments.
=head1 SYNOPSIS
......@@ -885,6 +885,7 @@ create watchers. Nothing special needs to be done by the main program.
AnyEvent::Impl::Event based on Event, very stable, few glitches.
AnyEvent::Impl::Glib based on Glib, slow but very stable.
AnyEvent::Impl::Tk based on Tk, very broken.
AnyEvent::Impl::UV based on UV, innovated square wheels.
AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse.
AnyEvent::Impl::POE based on POE, very slow, some limitations.
AnyEvent::Impl::Irssi used when running within irssi.
......@@ -1035,7 +1036,7 @@ asynchronously does something for you and returns some transaction
object or guard to let you cancel the operation. For example,
C<AnyEvent::Socket::tcp_connect>:
# start a conenction attempt unless one is active
# start a connection attempt unless one is active
$self->{connect_guard} ||= AnyEvent::Socket::tcp_connect "www.example.net", 80, sub {
delete $self->{connect_guard};
...
......@@ -1079,6 +1080,12 @@ creating a logger callback with the C<AnyEvent::Log::logger> function,
which can reduce typing, codesize and can reduce the logging overhead
enourmously.
=item AnyEvent::fh_block $filehandle
=item AnyEvent::fh_unblock $filehandle
Sets blocking or non-blocking behaviour for the given filehandle.
=back
=head1 WHAT TO DO IN A MODULE
......@@ -1249,7 +1256,7 @@ BEGIN {
use Carp ();
our $VERSION = '7.07';
our $VERSION = 7.11;
our $MODEL;
our @ISA;
our @REGISTRY;
......@@ -1356,6 +1363,25 @@ if (length $ENV{PERL_ANYEVENT_LOG}) {
require AnyEvent::Log; # AnyEvent::Log does the thing for us
}
BEGIN {
*_fh_nonblocking = AnyEvent::WIN32
? sub($$) {
ioctl $_[0], 0x8004667e, pack "L", $_[1]; # FIONBIO
}
: sub($$) {
fcntl $_[0], AnyEvent::F_SETFL, $_[1] ? AnyEvent::O_NONBLOCK : 0;
}
;
}
sub fh_block($) {
_fh_nonblocking shift, 0
}
sub fh_unblock($) {
_fh_nonblocking shift, 1
}
our @models = (
[EV:: => AnyEvent::Impl::EV::],
[AnyEvent::Loop:: => AnyEvent::Impl::Perl::],
......@@ -1368,6 +1394,7 @@ our @models = (
# everything below here should not be autoloaded
[Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy
[Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles
[UV:: => AnyEvent::Impl::UV::], # switched from libev, added back all bugs imaginable
[Qt:: => AnyEvent::Impl::Qt::], # requires special main program
[POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza
[Wx:: => AnyEvent::Impl::POE::],
......@@ -1566,7 +1593,7 @@ package AE;
our $VERSION = $AnyEvent::VERSION;
sub _reset() {
eval q{
eval q{
# fall back to the main API by default - backends and AnyEvent::Base
# implementations can overwrite these.
......@@ -2212,7 +2239,7 @@ list.
This variable can effectively be used for denial-of-service attacks
against local programs (e.g. when setuid), although the impact is likely
small, as the program has to handle conenction and other failures anyways.
small, as the program has to handle connection and other failures anyways.
Examples: C<PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6> - prefer IPv4 over IPv6,
but support both and try to use both. C<PERL_ANYEVENT_PROTOCOLS=ipv4>
......@@ -3043,13 +3070,13 @@ L<AnyEvent::Debug> (interactive shell, watcher tracing).
Supported event modules: L<AnyEvent::Loop>, L<EV>, L<EV::Glib>,
L<Glib::EV>, L<Event>, L<Glib::Event>, L<Glib>, L<Tk>, L<Event::Lib>,
L<Qt>, L<POE>, L<FLTK>.
L<Qt>, L<POE>, L<FLTK>, L<Cocoa::EventLoop>, L<UV>.
Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>,
L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>,
L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>,
L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>, L<Anyevent::Impl::Irssi>,
L<AnyEvent::Impl::FLTK>.
L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>, L<AnyEvent::Impl::Irssi>,
L<AnyEvent::Impl::FLTK>, L<AnyEvent::Impl::Cocoa>, L<AnyEvent::Impl::UV>.
Non-blocking handles, pipes, stream sockets, TCP clients and
servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>.
......
......@@ -47,9 +47,9 @@ our @DNS_FALLBACK; # some public dns servers as fallback
my $ipv4 = $prep->(
["08080808", "08080404"], # 8.8.8.8, 8.8.4.4 - google public dns
# ["d1f40003", "d1f30004"], # v209.244.0.3/4 - resolver1/2.level3.net - status unknown
["04020201", "04020203", "04020204", "04020205", "04020206"], # v4.2.2.1/3/4/5/6 - vnsc-pri.sys.gtei.net - effectively public
["cdd22ad2", "4044c8c8"], # 205.210.42.205, 64.68.200.200 - cache1/2.dnsresolvers.com - verified public
## ["d1f40003", "d1f30004"], # v209.244.0.3/4 - resolver1/2.level3.net - status unknown
## ["04020201", "04020203", "04020204", "04020205", "04020206"], # v4.2.2.1/3/4/5/6 - vnsc-pri.sys.gtei.net - effectively public
## ["cdd22ad2", "4044c8c8"], # 205.210.42.205, 64.68.200.200 - cache1/2.dnsresolvers.com - verified public
# ["8d010101"], # 141.1.1.1 - cable&wireless - status unknown
);
......@@ -698,7 +698,7 @@ resolver object.
The resolver is created with the following parameters:
untaint enabled
max_outstanding $ENV{PERL_ANYEVENT_MAX_OUTSTANDING_DNS}
max_outstanding $ENV{PERL_ANYEVENT_MAX_OUTSTANDING_DNS} (default 10)
C<os_config> will be used for OS-specific configuration, unless
C<$ENV{PERL_ANYEVENT_RESOLV_CONF}> is specified, in which case that file
......@@ -722,7 +722,7 @@ sub resolver() {
$RESOLVER || do {
$RESOLVER = new AnyEvent::DNS
untaint => 1,
max_outstanding => $ENV{PERL_ANYEVENT_MAX_OUTSTANDING_DNS}*1 || 1,
max_outstanding => $ENV{PERL_ANYEVENT_MAX_OUTSTANDING_DNS}*1 || 10,
;
$ENV{PERL_ANYEVENT_RESOLV_CONF}
......@@ -812,7 +812,7 @@ sub new {
if (socket my $fh4, AF_INET , Socket::SOCK_DGRAM(), 0) {
++$got_socket;
AnyEvent::Util::fh_nonblocking $fh4, 1;
AnyEvent::fh_unblock $fh4;
$self->{fh4} = $fh4;
$self->{rw4} = AE::io $fh4, 0, sub {
if (my $peer = recv $fh4, my $pkt, MAX_PKT, 0) {
......@@ -825,7 +825,7 @@ sub new {
++$got_socket;
$self->{fh6} = $fh6;
AnyEvent::Util::fh_nonblocking $fh6, 1;
AnyEvent::fh_unblock $fh6;
$self->{rw6} = AE::io $fh6, 0, sub {
if (my $peer = recv $fh6, my $pkt, MAX_PKT, 0) {
$wself->_recv ($pkt, $peer);
......
......@@ -46,7 +46,7 @@ our %STRCACHE;
This function binds on the given host and service port and returns a
shell object, which determines the lifetime of the shell. Any number
of conenctions are accepted on the port, and they will give you a very
of connections are accepted on the port, and they will give you a very
primitive shell that simply executes every line you enter.
All commands will be executed "blockingly" with the socket C<select>ed for
......@@ -122,13 +122,13 @@ sub shell($$) {
$logger_guard if 0; # reference it
if (defined $len ? $len == 0 : $! != Errno::EAGAIN) {
if (defined $len ? $len == 0 : ($! != Errno::EAGAIN && $! != Errno::EWOULDBLOCK)) {
undef $rw;
} else {
while ($rbuf =~ s/^(.*)\015?\012//) {
my $line = $1;
AnyEvent::Util::fh_nonblocking $fh, 0;
AnyEvent::fh_block $fh;
if ($line =~ /^\s*exit\b/) {
syswrite $fh, "sorry, no... if you want to execute exit, try CORE::exit.\015\012";
......@@ -175,7 +175,7 @@ sub shell($$) {
}
syswrite $fh, "> ";
AnyEvent::Util::fh_nonblocking $fh, 1;
AnyEvent::fh_unblock $fh;
}
}
};
......@@ -646,7 +646,7 @@ sub verbose {
my $res = "type: $self->{type} watcher\n"
. "args: " . (join " ", %{ $self->{arg} }) . "\n" # TODO: decode fh?
. "created: " . (AnyEvent::Log::ft $self->{now}) . " ($self->{now})\n"
. "created: " . (AnyEvent::Log::format_time $self->{now}) . " ($self->{now})\n"
. "file: ${ $self->{rfile} }\n"
. "line: $self->{line}\n"
. "subname: $self->{sub}\n"
......@@ -662,7 +662,7 @@ sub verbose {
if (exists $self->{error}) {
$res .= "errors: " . @{$self->{error}} . "\n";
$res .= "error: " . (AnyEvent::Log::ft $_->[0]) . " ($_->[0]) $_->[1]\n"
$res .= "error: " . (AnyEvent::Log::format_time $_->[0]) . " ($_->[0]) $_->[1]\n"
for @{$self->{error}};
}
......
......@@ -32,8 +32,10 @@ AnyEvent::Handle - non-blocking I/O on streaming handles via AnyEvent
=head1 DESCRIPTION
This is a helper module to make it easier to do event-based I/O on
stream-based filehandles (sockets, pipes, and other stream things).
This is a helper module to make it easier to do event-based I/O
on stream-based filehandles (sockets, pipes, and other stream
things). Specifically, it doesn't work as expected on files, packet-based
sockets or similar things.
The L<AnyEvent::Intro> tutorial contains some well-documented
AnyEvent::Handle examples.
......@@ -55,7 +57,7 @@ package AnyEvent::Handle;
use Scalar::Util ();
use List::Util ();
use Carp ();
use Errno qw(EAGAIN EINTR);
use Errno qw(EAGAIN EWOULDBLOCK EINTR);
use AnyEvent (); BEGIN { AnyEvent::common_sense }
use AnyEvent::Util qw(WSAEWOULDBLOCK);
......@@ -93,7 +95,7 @@ The constructor supports these arguments (all as C<< key => value >> pairs).
The filehandle this L<AnyEvent::Handle> object will operate on.
NOTE: The filehandle will be set to non-blocking mode (using
C<AnyEvent::Util::fh_nonblocking>) by the constructor and needs to stay in
C<AnyEvent::fh_unblock>) by the constructor and needs to stay in
that mode.
=item connect => [$host, $service] [C<fh> or C<connect> MANDATORY]
......@@ -134,9 +136,6 @@ parameters, together with a retry callback. 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.
It is not allowed to use the read or write queues while the handle object
is connecting.
If, for some reason, the handle is not acceptable, calling C<$retry> will
continue with the next connection target (in case of multi-homed hosts or
SRV records there can be multiple connection endpoints). The C<$retry>
......@@ -503,8 +502,26 @@ underlying handle signals EOF.
This is the json coder object used by the C<json> read and write types.
If you don't supply it, then AnyEvent::Handle will create and use a
suitable one (on demand), which will write and expect UTF-8 encoded JSON
texts.
suitable one (on demand), which will write and expect UTF-8 encoded
JSON texts (either using L<JSON::XS> or L<JSON>). The written texts are
guaranteed not to contain any newline character.
For security reasons, this encoder will likely I<not> handle numbers and
strings, only arrays and objects/hashes. The reason is that originally
JSON was self-delimited, but Dougles Crockford thought it was a splendid
idea to redefine JSON incompatibly, so this is no longer true.
For protocols that used back-to-back JSON texts, this might lead to
run-ins, where two or more JSON texts will be interpreted as one JSON
text.
For this reason, if the default encoder uses L<JSON::XS>, it will default
to not allowing anything but arrays and objects/hashes, at least for the
forseeable future (it will change at some point). This might or might not
be true for the L<JSON> module, so this might cause a security issue.
If you depend on either behaviour, you should create your own json object
and pass it in explicitly.
=item cbor => L<CBOR::XS> object
......@@ -512,7 +529,7 @@ This is the cbor coder object used by the C<cbor> read and write types.
If you don't supply it, then AnyEvent::Handle will create and use a
suitable one (on demand), which will write CBOR without using extensions,
if possible. texts.
if possible.
Note that you are responsible to depend on the L<CBOR::XS> module if you
want to use this functionality, as AnyEvent does not have a dependency on
......@@ -598,7 +615,7 @@ sub _start {
Carp::croak "AnyEvent::Handle: only stream sockets supported, anything else will NOT work!"
if Socket::SOCK_STREAM () != (unpack "I", $type) && defined $type;
AnyEvent::Util::fh_nonblocking $self->{fh}, 1;
AnyEvent::fh_unblock $self->{fh};
$self->{_activity} =
$self->{_ractivity} =
......@@ -958,7 +975,7 @@ sub _drain_wbuf {
&& $self->{on_drain};
delete $self->{_ww} unless length $self->{wbuf};
} elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) {
} elsif ($! != EAGAIN && $! != EINTR && $! != EWOULDBLOCK && $! != WSAEWOULDBLOCK) {
$self->_error ($!, 1);
}
};
......@@ -1056,13 +1073,18 @@ Encodes the given hash or array reference into a JSON object. Unless you
provide your own JSON object, this means it will be encoded to JSON text
in UTF-8.
JSON objects (and arrays) are self-delimiting, so you can write JSON at
one end of a handle and read them at the other end without using any
additional framing.
The default encoder might or might not handle every type of JSON value -
it might be limited to arrays and objects for security reasons. See the
C<json> constructor attribute for more details.
JSON objects (and arrays) are self-delimiting, so if you only use arrays
and hashes, you can write JSON at one end of a handle and read them at the
other end without using any additional framing.
The generated JSON text is guaranteed not to contain any newlines: While
this module doesn't need delimiters after or between JSON texts to be
able to read them, many other languages depend on that.
The JSON text generated by the default encoder is guaranteed not to
contain any newlines: While this module doesn't need delimiters after or
between JSON texts to be able to read them, many other languages depend on
them.
A simple RPC protocol that interoperates easily with other languages is
to send JSON arrays (or objects, although arrays are usually the better
......@@ -1552,7 +1574,8 @@ register_read_type line => sub {
=item regex => $accept[, $reject[, $skip], $cb->($handle, $data)
Makes a regex match against the regex object C<$accept> and returns
everything up to and including the match.
everything up to and including the match. All the usual regex variables
($1, %+ etc.) from the regex match are available in the callback.
Example: read a single line terminated by '\n'.
......@@ -2020,7 +2043,7 @@ sub start_read {
$self->{_eof} = 1;
$self->_drain_rbuf;
} elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) {
} elsif ($! != EAGAIN && $! != EINTR && $! != EWOULDBLOCK && $! != WSAEWOULDBLOCK) {
return $self->_error ($!, 1);
}
};
......@@ -2286,7 +2309,7 @@ sub DESTROY {
if ($len > 0) {
substr $wbuf, 0, $len, "";
} elsif (defined $len || ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK)) {
} elsif (defined $len || ($! != EAGAIN && $! != EINTR && $! != EWOULDBLOCK && $! != WSAEWOULDBLOCK)) {
@linger = (); # end
}
};
......
......@@ -19,10 +19,22 @@ Glib is probably the most inefficient event loop that has ever seen the
light of the world: Glib not only scans all its watchers (really, ALL of
them, whether I/O-related, timer-related or what not) during each loop
iteration, it also does so multiple times and rebuilds the poll list for
the kernel each time again, dynamically even.
the kernel each time again, dynamically even. Newer versions of libglib
fortunately do not call malloc/free on every single watcher invocation,
though.
On the positive side, and most importantly, Glib generally works
correctly, no quarrels there.
Glib also enforces certain undocumented behaviours, for example, you
cannot always remove active child watchers, and the conditions on when
it is valid to do so are not documented. Of course, if you get it wrong,
you get "GLib-CRITICAL" messages. This makes it extremely hard to write
"correct" glib programs, as you have to study the source code to get it
right, and hope future versions don't change any internals.
AnyEvent implements the necessary workarounds, at a small performance
cost.
On the positive side, and most importantly, when it works, Glib generally
works correctly, no quarrels there.
If you create many watchers (as in: more than two), you might consider one
of the L<Glib::EV>, L<EV::Glib> or L<Glib::Event> modules that map Glib to
......@@ -70,9 +82,18 @@ sub timer {
remove Glib::Source $source;
$source = add Glib::Timeout $ival, sub { &$cb; 1 };
&$cb;
0
1 # already removed, should be a nop
}
: sub { &$cb; 0 };
: sub {
# due to the braindamaged libglib API (it manages
# removed-but-active watchers internally, but forces
# users to # manage the same externally as well),
# we have to go through these contortions.
remove Glib::Source $source;
undef $source;
&$cb;
1 # already removed, should be a nop
};
bless \\$source, $class
}
......@@ -87,7 +108,8 @@ sub idle {
}
sub DESTROY {
remove Glib::Source $${$_[0]};
remove Glib::Source $${$_[0]}
if defined $${$_[0]};
}
our %pid_w;
......@@ -105,10 +127,16 @@ sub child {
$pid_cb{$pid}{$cb+0} = $cb;
$pid_w{$pid} ||= Glib::Child->watch_add ($pid, sub {
# the unbelievably braindamaged glib api ignores the return
# value and always removes the watcher (this is of course
# undocumented), so we need to go through these contortions to
# work around this, here and in DESTROY.
undef $pid_w{$pid};
$_->($_[0], $_[1])
for values %{ $pid_cb{$pid} };
1
1 # gets ignored
});
bless [$pid, $cb+0], "AnyEvent::Impl::Glib::child"
......@@ -120,7 +148,8 @@ sub AnyEvent::Impl::Glib::child::DESTROY {
delete $pid_cb{$pid}{$icb};
unless (%{ $pid_cb{$pid} }) {
delete $pid_cb{$pid};
remove Glib::Source delete $pid_w{$pid};
my $source = delete $pid_w{$pid};
remove Glib::Source if defined $source;
}
}
......
=head1 NAME
AnyEvent::Impl::UV - AnyEvent adaptor for UV
=head1 SYNOPSIS
use AnyEvent;
use UV;
# this module gets loaded automatically as required
=head1 DESCRIPTION
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);
@_
}
# https://github.com/joyent/libuv/issues/680
# https://github.com/joyent/libuv/blob/dc1ea27c736f0d21c7160c790bcd1b113d20abd9/include/uv.h#L1277
my %io_watchers;
sub io_watcher_cb {
my $slaves = shift;
my (undef, $events) = @_;
return unless defined $slaves;
foreach my $entry (keys %$slaves) {
my $slave = $slaves->{$entry};
$slave->{cb}(@_) if $slave->{mode} & $events;
}
}
sub AnyEvent::Impl::UV::io_slave::new {
bless { parent => $_[1] }, $_[0]
}
sub AnyEvent::Impl::UV::io_slave::DESTROY {
my $self = $_[0];
my $master = $self->{parent};
delete $master->{slaves}{$self};
if (keys %{$master->{slaves}} == 0) {
if (defined $master->{w}) {
my $rc = UV::poll_stop $master->{w};
<