… | |
… | |
33 | |
33 | |
34 | BEGIN { |
34 | BEGIN { |
35 | *socket_inet_aton = \&Socket::inet_aton; # take a copy, in case Coro::LWP overrides it |
35 | *socket_inet_aton = \&Socket::inet_aton; # take a copy, in case Coro::LWP overrides it |
36 | } |
36 | } |
37 | |
37 | |
|
|
38 | BEGIN { |
|
|
39 | my $af_inet6 = eval { &Socket::AF_INET6 }; |
|
|
40 | eval "sub AF_INET6() { $af_inet6 }"; die if $@; |
|
|
41 | |
|
|
42 | delete $AnyEvent::PROTOCOL{ipv6} unless $af_inet6; |
|
|
43 | } |
|
|
44 | |
|
|
45 | BEGIN { |
|
|
46 | # broken windows perls use undocumented error codes... |
|
|
47 | if ($^O =~ /mswin32/i) { |
|
|
48 | eval "sub WSAEAGAIN() { 10035 }"; |
|
|
49 | } else { |
|
|
50 | eval "sub WSAEAGAIN() { -1e99 }"; # should never match any errno value |
|
|
51 | } |
|
|
52 | } |
|
|
53 | |
38 | our @EXPORT = qw(fh_nonblocking guard); |
54 | our @EXPORT = qw(fh_nonblocking guard); |
|
|
55 | our @EXPORT_OK = qw(AF_INET6 WSAEAGAIN); |
39 | |
56 | |
40 | our $VERSION = '1.0'; |
57 | our $VERSION = '1.0'; |
41 | |
58 | |
42 | our $MAXPARALLEL = 16; # max. number of parallel jobs |
59 | our $MAXPARALLEL = 16; # max. number of parallel jobs |
43 | |
60 | |
… | |
… | |
123 | code block. |
140 | code block. |
124 | |
141 | |
125 | This is often handy in continuation-passing style code to clean up some |
142 | This is often handy in continuation-passing style code to clean up some |
126 | resource regardless of where you break out of a process. |
143 | resource regardless of where you break out of a process. |
127 | |
144 | |
|
|
145 | You can call one method on the returned object: |
|
|
146 | |
|
|
147 | =item $guard->cancel |
|
|
148 | |
|
|
149 | This simply causes the code block not to be invoked: it "cancels" the |
|
|
150 | guard. |
|
|
151 | |
128 | =cut |
152 | =cut |
129 | |
153 | |
130 | sub AnyEvent::Util::Guard::DESTROY { |
154 | sub AnyEvent::Util::Guard::DESTROY { |
131 | ${$_[0]}->(); |
155 | ${$_[0]}->(); |
|
|
156 | } |
|
|
157 | |
|
|
158 | sub AnyEvent::Util::Guard::cancel($) { |
|
|
159 | ${$_[0]} = sub { }; |
132 | } |
160 | } |
133 | |
161 | |
134 | sub guard(&) { |
162 | sub guard(&) { |
135 | bless \(my $cb = shift), AnyEvent::Util::Guard:: |
163 | bless \(my $cb = shift), AnyEvent::Util::Guard:: |
136 | } |
164 | } |