1 | package AnyEvent::Handle; |
1 | package AnyEvent::Handle; |
2 | |
2 | |
3 | no warnings; |
3 | no warnings; |
4 | use strict; |
4 | use strict qw(subs vars); |
5 | |
5 | |
6 | use AnyEvent (); |
6 | use AnyEvent (); |
7 | use AnyEvent::Util qw(WSAWOULDBLOCK); |
7 | use AnyEvent::Util qw(WSAEWOULDBLOCK); |
8 | use Scalar::Util (); |
8 | use Scalar::Util (); |
9 | use Carp (); |
9 | use Carp (); |
10 | use Fcntl (); |
10 | use Fcntl (); |
11 | use Errno qw/EAGAIN EINTR/; |
11 | use Errno qw(EAGAIN EINTR); |
12 | |
12 | |
13 | =head1 NAME |
13 | =head1 NAME |
14 | |
14 | |
15 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
15 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
16 | |
16 | |
17 | =cut |
17 | =cut |
18 | |
18 | |
19 | our $VERSION = '0.04'; |
19 | our $VERSION = 4.22; |
20 | |
20 | |
21 | =head1 SYNOPSIS |
21 | =head1 SYNOPSIS |
22 | |
22 | |
23 | use AnyEvent; |
23 | use AnyEvent; |
24 | use AnyEvent::Handle; |
24 | use AnyEvent::Handle; |
… | |
… | |
73 | The filehandle this L<AnyEvent::Handle> object will operate on. |
73 | The filehandle this L<AnyEvent::Handle> object will operate on. |
74 | |
74 | |
75 | NOTE: The filehandle will be set to non-blocking (using |
75 | NOTE: The filehandle will be set to non-blocking (using |
76 | AnyEvent::Util::fh_nonblocking). |
76 | AnyEvent::Util::fh_nonblocking). |
77 | |
77 | |
78 | =item on_eof => $cb->($self) |
78 | =item on_eof => $cb->($handle) |
79 | |
79 | |
80 | Set the callback to be called on EOF. |
80 | Set the callback to be called when an end-of-file condition is detected, |
|
|
81 | i.e. in the case of a socket, when the other side has closed the |
|
|
82 | connection cleanly. |
81 | |
83 | |
82 | While not mandatory, it is highly recommended to set an eof callback, |
84 | While not mandatory, it is I<highly> recommended to set an eof callback, |
83 | otherwise you might end up with a closed socket while you are still |
85 | otherwise you might end up with a closed socket while you are still |
84 | waiting for data. |
86 | waiting for data. |
85 | |
87 | |
|
|
88 | If an EOF condition has been detected but no C<on_eof> callback has been |
|
|
89 | set, then a fatal error will be raised with C<$!> set to <0>. |
|
|
90 | |
86 | =item on_error => $cb->($self) |
91 | =item on_error => $cb->($handle, $fatal) |
87 | |
92 | |
88 | This is the fatal error callback, that is called when, well, a fatal error |
93 | This is the error callback, which is called when, well, some error |
89 | occurs, such as not being able to resolve the hostname, failure to connect |
94 | occured, such as not being able to resolve the hostname, failure to |
90 | or a read error. |
95 | connect or a read error. |
91 | |
96 | |
92 | The object will not be in a usable state when this callback has been |
97 | Some errors are fatal (which is indicated by C<$fatal> being true). On |
93 | called. |
98 | fatal errors the handle object will be shut down and will not be |
|
|
99 | usable. Non-fatal errors can be retried by simply returning, but it is |
|
|
100 | recommended to simply ignore this parameter and instead abondon the handle |
|
|
101 | object when this callback is invoked. |
94 | |
102 | |
95 | On callback entrance, the value of C<$!> contains the operating system |
103 | On callback entrance, the value of C<$!> contains the operating system |
96 | error (or C<ENOSPC>, C<EPIPE> or C<EBADMSG>). |
104 | error (or C<ENOSPC>, C<EPIPE>, C<ETIMEDOUT> or C<EBADMSG>). |
97 | |
|
|
98 | The callbakc should throw an exception. If it returns, then |
|
|
99 | AnyEvent::Handle will C<croak> for you. |
|
|
100 | |
105 | |
101 | While not mandatory, it is I<highly> recommended to set this callback, as |
106 | While not mandatory, it is I<highly> recommended to set this callback, as |
102 | you will not be notified of errors otherwise. The default simply calls |
107 | you will not be notified of errors otherwise. The default simply calls |
103 | die. |
108 | C<croak>. |
104 | |
109 | |
105 | =item on_read => $cb->($self) |
110 | =item on_read => $cb->($handle) |
106 | |
111 | |
107 | This sets the default read callback, which is called when data arrives |
112 | This sets the default read callback, which is called when data arrives |
108 | and no read request is in the queue. |
113 | and no read request is in the queue (unlike read queue callbacks, this |
|
|
114 | callback will only be called when at least one octet of data is in the |
|
|
115 | read buffer). |
109 | |
116 | |
110 | To access (and remove data from) the read buffer, use the C<< ->rbuf >> |
117 | To access (and remove data from) the read buffer, use the C<< ->rbuf >> |
111 | method or access the C<$self->{rbuf}> member directly. |
118 | method or access the C<$handle->{rbuf}> member directly. |
112 | |
119 | |
113 | When an EOF condition is detected then AnyEvent::Handle will first try to |
120 | When an EOF condition is detected then AnyEvent::Handle will first try to |
114 | feed all the remaining data to the queued callbacks and C<on_read> before |
121 | feed all the remaining data to the queued callbacks and C<on_read> before |
115 | calling the C<on_eof> callback. If no progress can be made, then a fatal |
122 | calling the C<on_eof> callback. If no progress can be made, then a fatal |
116 | error will be raised (with C<$!> set to C<EPIPE>). |
123 | error will be raised (with C<$!> set to C<EPIPE>). |
117 | |
124 | |
118 | =item on_drain => $cb->() |
125 | =item on_drain => $cb->($handle) |
119 | |
126 | |
120 | This sets the callback that is called when the write buffer becomes empty |
127 | This sets the callback that is called when the write buffer becomes empty |
121 | (or when the callback is set and the buffer is empty already). |
128 | (or when the callback is set and the buffer is empty already). |
122 | |
129 | |
123 | To append to the write buffer, use the C<< ->push_write >> method. |
130 | To append to the write buffer, use the C<< ->push_write >> method. |
|
|
131 | |
|
|
132 | This callback is useful when you don't want to put all of your write data |
|
|
133 | into the queue at once, for example, when you want to write the contents |
|
|
134 | of some file to the socket you might not want to read the whole file into |
|
|
135 | memory and push it into the queue, but instead only read more data from |
|
|
136 | the file when the write queue becomes empty. |
|
|
137 | |
|
|
138 | =item timeout => $fractional_seconds |
|
|
139 | |
|
|
140 | If non-zero, then this enables an "inactivity" timeout: whenever this many |
|
|
141 | seconds pass without a successful read or write on the underlying file |
|
|
142 | handle, the C<on_timeout> callback will be invoked (and if that one is |
|
|
143 | missing, an C<ETIMEDOUT> error will be raised). |
|
|
144 | |
|
|
145 | Note that timeout processing is also active when you currently do not have |
|
|
146 | any outstanding read or write requests: If you plan to keep the connection |
|
|
147 | idle then you should disable the timout temporarily or ignore the timeout |
|
|
148 | in the C<on_timeout> callback. |
|
|
149 | |
|
|
150 | Zero (the default) disables this timeout. |
|
|
151 | |
|
|
152 | =item on_timeout => $cb->($handle) |
|
|
153 | |
|
|
154 | Called whenever the inactivity timeout passes. If you return from this |
|
|
155 | callback, then the timeout will be reset as if some activity had happened, |
|
|
156 | so this condition is not fatal in any way. |
124 | |
157 | |
125 | =item rbuf_max => <bytes> |
158 | =item rbuf_max => <bytes> |
126 | |
159 | |
127 | If defined, then a fatal error will be raised (with C<$!> set to C<ENOSPC>) |
160 | If defined, then a fatal error will be raised (with C<$!> set to C<ENOSPC>) |
128 | when the read buffer ever (strictly) exceeds this size. This is useful to |
161 | when the read buffer ever (strictly) exceeds this size. This is useful to |
… | |
… | |
132 | be configured to accept only so-and-so much data that it cannot act on |
165 | be configured to accept only so-and-so much data that it cannot act on |
133 | (for example, when expecting a line, an attacker could send an unlimited |
166 | (for example, when expecting a line, an attacker could send an unlimited |
134 | amount of data without a callback ever being called as long as the line |
167 | amount of data without a callback ever being called as long as the line |
135 | isn't finished). |
168 | isn't finished). |
136 | |
169 | |
|
|
170 | =item autocork => <boolean> |
|
|
171 | |
|
|
172 | When disabled (the default), then C<push_write> will try to immediately |
|
|
173 | write the data to the handle if possible. This avoids having to register |
|
|
174 | a write watcher and wait for the next event loop iteration, but can be |
|
|
175 | inefficient if you write multiple small chunks (this disadvantage is |
|
|
176 | usually avoided by your kernel's nagle algorithm, see C<low_delay>). |
|
|
177 | |
|
|
178 | When enabled, then writes will always be queued till the next event loop |
|
|
179 | iteration. This is efficient when you do many small writes per iteration, |
|
|
180 | but less efficient when you do a single write only. |
|
|
181 | |
|
|
182 | =item no_delay => <boolean> |
|
|
183 | |
|
|
184 | When doing small writes on sockets, your operating system kernel might |
|
|
185 | wait a bit for more data before actually sending it out. This is called |
|
|
186 | the Nagle algorithm, and usually it is beneficial. |
|
|
187 | |
|
|
188 | In some situations you want as low a delay as possible, which cna be |
|
|
189 | accomplishd by setting this option to true. |
|
|
190 | |
|
|
191 | The default is your opertaing system's default behaviour, this option |
|
|
192 | explicitly enables or disables it, if possible. |
|
|
193 | |
137 | =item read_size => <bytes> |
194 | =item read_size => <bytes> |
138 | |
195 | |
139 | The default read block size (the amount of bytes this module will try to read |
196 | The default read block size (the amount of bytes this module will try to read |
140 | on each [loop iteration). Default: C<4096>. |
197 | during each (loop iteration). Default: C<8192>. |
141 | |
198 | |
142 | =item low_water_mark => <bytes> |
199 | =item low_water_mark => <bytes> |
143 | |
200 | |
144 | Sets the amount of bytes (default: C<0>) that make up an "empty" write |
201 | Sets the amount of bytes (default: C<0>) that make up an "empty" write |
145 | buffer: If the write reaches this size or gets even samller it is |
202 | buffer: If the write reaches this size or gets even samller it is |
146 | considered empty. |
203 | considered empty. |
|
|
204 | |
|
|
205 | =item linger => <seconds> |
|
|
206 | |
|
|
207 | If non-zero (default: C<3600>), then the destructor of the |
|
|
208 | AnyEvent::Handle object will check wether there is still outstanding write |
|
|
209 | data and will install a watcher that will write out this data. No errors |
|
|
210 | will be reported (this mostly matches how the operating system treats |
|
|
211 | outstanding data at socket close time). |
|
|
212 | |
|
|
213 | This will not work for partial TLS data that could not yet been |
|
|
214 | encoded. This data will be lost. |
147 | |
215 | |
148 | =item tls => "accept" | "connect" | Net::SSLeay::SSL object |
216 | =item tls => "accept" | "connect" | Net::SSLeay::SSL object |
149 | |
217 | |
150 | When this parameter is given, it enables TLS (SSL) mode, that means it |
218 | When this parameter is given, it enables TLS (SSL) mode, that means it |
151 | will start making tls handshake and will transparently encrypt/decrypt |
219 | will start making tls handshake and will transparently encrypt/decrypt |
… | |
… | |
160 | You can also provide your own TLS connection object, but you have |
228 | You can also provide your own TLS connection object, but you have |
161 | to make sure that you call either C<Net::SSLeay::set_connect_state> |
229 | to make sure that you call either C<Net::SSLeay::set_connect_state> |
162 | or C<Net::SSLeay::set_accept_state> on it before you pass it to |
230 | or C<Net::SSLeay::set_accept_state> on it before you pass it to |
163 | AnyEvent::Handle. |
231 | AnyEvent::Handle. |
164 | |
232 | |
165 | See the C<starttls> method if you need to start TLs negotiation later. |
233 | See the C<starttls> method if you need to start TLS negotiation later. |
166 | |
234 | |
167 | =item tls_ctx => $ssl_ctx |
235 | =item tls_ctx => $ssl_ctx |
168 | |
236 | |
169 | Use the given Net::SSLeay::CTX object to create the new TLS connection |
237 | Use the given Net::SSLeay::CTX object to create the new TLS connection |
170 | (unless a connection object was specified directly). If this parameter is |
238 | (unless a connection object was specified directly). If this parameter is |
171 | missing, then AnyEvent::Handle will use C<AnyEvent::Handle::TLS_CTX>. |
239 | missing, then AnyEvent::Handle will use C<AnyEvent::Handle::TLS_CTX>. |
172 | |
240 | |
|
|
241 | =item json => JSON or JSON::XS object |
|
|
242 | |
|
|
243 | This is the json coder object used by the C<json> read and write types. |
|
|
244 | |
|
|
245 | If you don't supply it, then AnyEvent::Handle will create and use a |
|
|
246 | suitable one, which will write and expect UTF-8 encoded JSON texts. |
|
|
247 | |
|
|
248 | Note that you are responsible to depend on the JSON module if you want to |
|
|
249 | use this functionality, as AnyEvent does not have a dependency itself. |
|
|
250 | |
|
|
251 | =item filter_r => $cb |
|
|
252 | |
|
|
253 | =item filter_w => $cb |
|
|
254 | |
|
|
255 | These exist, but are undocumented at this time. |
|
|
256 | |
173 | =back |
257 | =back |
174 | |
258 | |
175 | =cut |
259 | =cut |
176 | |
260 | |
177 | sub new { |
261 | sub new { |
… | |
… | |
186 | if ($self->{tls}) { |
270 | if ($self->{tls}) { |
187 | require Net::SSLeay; |
271 | require Net::SSLeay; |
188 | $self->starttls (delete $self->{tls}, delete $self->{tls_ctx}); |
272 | $self->starttls (delete $self->{tls}, delete $self->{tls_ctx}); |
189 | } |
273 | } |
190 | |
274 | |
191 | $self->on_eof (delete $self->{on_eof} ) if $self->{on_eof}; |
275 | $self->{_activity} = AnyEvent->now; |
192 | $self->on_error (delete $self->{on_error}) if $self->{on_error}; |
276 | $self->_timeout; |
|
|
277 | |
193 | $self->on_drain (delete $self->{on_drain}) if $self->{on_drain}; |
278 | $self->on_drain (delete $self->{on_drain}) if exists $self->{on_drain}; |
194 | $self->on_read (delete $self->{on_read} ) if $self->{on_read}; |
279 | $self->no_delay (delete $self->{no_delay}) if exists $self->{no_delay}; |
195 | |
280 | |
196 | $self->start_read; |
281 | $self->start_read |
|
|
282 | if $self->{on_read}; |
197 | |
283 | |
198 | $self |
284 | $self |
199 | } |
285 | } |
200 | |
286 | |
201 | sub _shutdown { |
287 | sub _shutdown { |
202 | my ($self) = @_; |
288 | my ($self) = @_; |
203 | |
289 | |
|
|
290 | delete $self->{_tw}; |
204 | delete $self->{rw}; |
291 | delete $self->{_rw}; |
205 | delete $self->{ww}; |
292 | delete $self->{_ww}; |
206 | delete $self->{fh}; |
293 | delete $self->{fh}; |
207 | } |
|
|
208 | |
294 | |
|
|
295 | $self->stoptls; |
|
|
296 | } |
|
|
297 | |
209 | sub error { |
298 | sub _error { |
210 | my ($self) = @_; |
299 | my ($self, $errno, $fatal) = @_; |
211 | |
300 | |
212 | { |
|
|
213 | local $!; |
|
|
214 | $self->_shutdown; |
301 | $self->_shutdown |
215 | } |
302 | if $fatal; |
216 | |
303 | |
217 | $self->{on_error}($self) |
304 | $! = $errno; |
|
|
305 | |
218 | if $self->{on_error}; |
306 | if ($self->{on_error}) { |
219 | |
307 | $self->{on_error}($self, $fatal); |
|
|
308 | } else { |
220 | Carp::croak "AnyEvent::Handle uncaught fatal error: $!"; |
309 | Carp::croak "AnyEvent::Handle uncaught error: $!"; |
|
|
310 | } |
221 | } |
311 | } |
222 | |
312 | |
223 | =item $fh = $handle->fh |
313 | =item $fh = $handle->fh |
224 | |
314 | |
225 | This method returns the file handle of the L<AnyEvent::Handle> object. |
315 | This method returns the file handle of the L<AnyEvent::Handle> object. |
226 | |
316 | |
227 | =cut |
317 | =cut |
228 | |
318 | |
229 | sub fh { $_[0]->{fh} } |
319 | sub fh { $_[0]{fh} } |
230 | |
320 | |
231 | =item $handle->on_error ($cb) |
321 | =item $handle->on_error ($cb) |
232 | |
322 | |
233 | Replace the current C<on_error> callback (see the C<on_error> constructor argument). |
323 | Replace the current C<on_error> callback (see the C<on_error> constructor argument). |
234 | |
324 | |
… | |
… | |
244 | |
334 | |
245 | =cut |
335 | =cut |
246 | |
336 | |
247 | sub on_eof { |
337 | sub on_eof { |
248 | $_[0]{on_eof} = $_[1]; |
338 | $_[0]{on_eof} = $_[1]; |
|
|
339 | } |
|
|
340 | |
|
|
341 | =item $handle->on_timeout ($cb) |
|
|
342 | |
|
|
343 | Replace the current C<on_timeout> callback, or disables the callback |
|
|
344 | (but not the timeout) if C<$cb> = C<undef>. See C<timeout> constructor |
|
|
345 | argument. |
|
|
346 | |
|
|
347 | =cut |
|
|
348 | |
|
|
349 | sub on_timeout { |
|
|
350 | $_[0]{on_timeout} = $_[1]; |
|
|
351 | } |
|
|
352 | |
|
|
353 | =item $handle->autocork ($boolean) |
|
|
354 | |
|
|
355 | Enables or disables the current autocork behaviour (see C<autocork> |
|
|
356 | constructor argument). |
|
|
357 | |
|
|
358 | =cut |
|
|
359 | |
|
|
360 | =item $handle->no_delay ($boolean) |
|
|
361 | |
|
|
362 | Enables or disables the C<no_delay> setting (see constructor argument of |
|
|
363 | the same name for details). |
|
|
364 | |
|
|
365 | =cut |
|
|
366 | |
|
|
367 | sub no_delay { |
|
|
368 | $_[0]{no_delay} = $_[1]; |
|
|
369 | |
|
|
370 | eval { |
|
|
371 | local $SIG{__DIE__}; |
|
|
372 | setsockopt $_[0]{fh}, &Socket::IPPROTO_TCP, &Socket::TCP_NODELAY, int $_[1]; |
|
|
373 | }; |
|
|
374 | } |
|
|
375 | |
|
|
376 | ############################################################################# |
|
|
377 | |
|
|
378 | =item $handle->timeout ($seconds) |
|
|
379 | |
|
|
380 | Configures (or disables) the inactivity timeout. |
|
|
381 | |
|
|
382 | =cut |
|
|
383 | |
|
|
384 | sub timeout { |
|
|
385 | my ($self, $timeout) = @_; |
|
|
386 | |
|
|
387 | $self->{timeout} = $timeout; |
|
|
388 | $self->_timeout; |
|
|
389 | } |
|
|
390 | |
|
|
391 | # reset the timeout watcher, as neccessary |
|
|
392 | # also check for time-outs |
|
|
393 | sub _timeout { |
|
|
394 | my ($self) = @_; |
|
|
395 | |
|
|
396 | if ($self->{timeout}) { |
|
|
397 | my $NOW = AnyEvent->now; |
|
|
398 | |
|
|
399 | # when would the timeout trigger? |
|
|
400 | my $after = $self->{_activity} + $self->{timeout} - $NOW; |
|
|
401 | |
|
|
402 | # now or in the past already? |
|
|
403 | if ($after <= 0) { |
|
|
404 | $self->{_activity} = $NOW; |
|
|
405 | |
|
|
406 | if ($self->{on_timeout}) { |
|
|
407 | $self->{on_timeout}($self); |
|
|
408 | } else { |
|
|
409 | $self->_error (&Errno::ETIMEDOUT); |
|
|
410 | } |
|
|
411 | |
|
|
412 | # callback could have changed timeout value, optimise |
|
|
413 | return unless $self->{timeout}; |
|
|
414 | |
|
|
415 | # calculate new after |
|
|
416 | $after = $self->{timeout}; |
|
|
417 | } |
|
|
418 | |
|
|
419 | Scalar::Util::weaken $self; |
|
|
420 | return unless $self; # ->error could have destroyed $self |
|
|
421 | |
|
|
422 | $self->{_tw} ||= AnyEvent->timer (after => $after, cb => sub { |
|
|
423 | delete $self->{_tw}; |
|
|
424 | $self->_timeout; |
|
|
425 | }); |
|
|
426 | } else { |
|
|
427 | delete $self->{_tw}; |
|
|
428 | } |
249 | } |
429 | } |
250 | |
430 | |
251 | ############################################################################# |
431 | ############################################################################# |
252 | |
432 | |
253 | =back |
433 | =back |
… | |
… | |
290 | =cut |
470 | =cut |
291 | |
471 | |
292 | sub _drain_wbuf { |
472 | sub _drain_wbuf { |
293 | my ($self) = @_; |
473 | my ($self) = @_; |
294 | |
474 | |
295 | if (!$self->{ww} && length $self->{wbuf}) { |
475 | if (!$self->{_ww} && length $self->{wbuf}) { |
296 | |
476 | |
297 | Scalar::Util::weaken $self; |
477 | Scalar::Util::weaken $self; |
298 | |
478 | |
299 | my $cb = sub { |
479 | my $cb = sub { |
300 | my $len = syswrite $self->{fh}, $self->{wbuf}; |
480 | my $len = syswrite $self->{fh}, $self->{wbuf}; |
301 | |
481 | |
302 | if ($len >= 0) { |
482 | if ($len >= 0) { |
303 | substr $self->{wbuf}, 0, $len, ""; |
483 | substr $self->{wbuf}, 0, $len, ""; |
|
|
484 | |
|
|
485 | $self->{_activity} = AnyEvent->now; |
304 | |
486 | |
305 | $self->{on_drain}($self) |
487 | $self->{on_drain}($self) |
306 | if $self->{low_water_mark} >= length $self->{wbuf} |
488 | if $self->{low_water_mark} >= length $self->{wbuf} |
307 | && $self->{on_drain}; |
489 | && $self->{on_drain}; |
308 | |
490 | |
309 | delete $self->{ww} unless length $self->{wbuf}; |
491 | delete $self->{_ww} unless length $self->{wbuf}; |
310 | } elsif ($! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK) { |
492 | } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) { |
311 | $self->error; |
493 | $self->_error ($!, 1); |
312 | } |
494 | } |
313 | }; |
495 | }; |
314 | |
496 | |
315 | # try to write data immediately |
497 | # try to write data immediately |
316 | $cb->(); |
498 | $cb->() unless $self->{autocork}; |
317 | |
499 | |
318 | # if still data left in wbuf, we need to poll |
500 | # if still data left in wbuf, we need to poll |
319 | $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb) |
501 | $self->{_ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb) |
320 | if length $self->{wbuf}; |
502 | if length $self->{wbuf}; |
321 | }; |
503 | }; |
322 | } |
504 | } |
323 | |
505 | |
324 | our %WH; |
506 | our %WH; |
… | |
… | |
336 | @_ = ($WH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_write") |
518 | @_ = ($WH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_write") |
337 | ->($self, @_); |
519 | ->($self, @_); |
338 | } |
520 | } |
339 | |
521 | |
340 | if ($self->{filter_w}) { |
522 | if ($self->{filter_w}) { |
341 | $self->{filter_w}->($self, \$_[0]); |
523 | $self->{filter_w}($self, \$_[0]); |
342 | } else { |
524 | } else { |
343 | $self->{wbuf} .= $_[0]; |
525 | $self->{wbuf} .= $_[0]; |
344 | $self->_drain_wbuf; |
526 | $self->_drain_wbuf; |
345 | } |
527 | } |
346 | } |
528 | } |
347 | |
529 | |
348 | =item $handle->push_write (type => @args) |
530 | =item $handle->push_write (type => @args) |
349 | |
531 | |
350 | =item $handle->unshift_write (type => @args) |
|
|
351 | |
|
|
352 | Instead of formatting your data yourself, you can also let this module do |
532 | Instead of formatting your data yourself, you can also let this module do |
353 | the job by specifying a type and type-specific arguments. |
533 | the job by specifying a type and type-specific arguments. |
354 | |
534 | |
355 | Predefined types are (if you have ideas for additional types, feel free to |
535 | Predefined types are (if you have ideas for additional types, feel free to |
356 | drop by and tell us): |
536 | drop by and tell us): |
… | |
… | |
360 | =item netstring => $string |
540 | =item netstring => $string |
361 | |
541 | |
362 | Formats the given value as netstring |
542 | Formats the given value as netstring |
363 | (http://cr.yp.to/proto/netstrings.txt, this is not a recommendation to use them). |
543 | (http://cr.yp.to/proto/netstrings.txt, this is not a recommendation to use them). |
364 | |
544 | |
365 | =back |
|
|
366 | |
|
|
367 | =cut |
545 | =cut |
368 | |
546 | |
369 | register_write_type netstring => sub { |
547 | register_write_type netstring => sub { |
370 | my ($self, $string) = @_; |
548 | my ($self, $string) = @_; |
371 | |
549 | |
372 | sprintf "%d:%s,", (length $string), $string |
550 | sprintf "%d:%s,", (length $string), $string |
373 | }; |
551 | }; |
374 | |
552 | |
|
|
553 | =item packstring => $format, $data |
|
|
554 | |
|
|
555 | An octet string prefixed with an encoded length. The encoding C<$format> |
|
|
556 | uses the same format as a Perl C<pack> format, but must specify a single |
|
|
557 | integer only (only one of C<cCsSlLqQiInNvVjJw> is allowed, plus an |
|
|
558 | optional C<!>, C<< < >> or C<< > >> modifier). |
|
|
559 | |
|
|
560 | =cut |
|
|
561 | |
|
|
562 | register_write_type packstring => sub { |
|
|
563 | my ($self, $format, $string) = @_; |
|
|
564 | |
|
|
565 | pack "$format/a*", $string |
|
|
566 | }; |
|
|
567 | |
|
|
568 | =item json => $array_or_hashref |
|
|
569 | |
|
|
570 | Encodes the given hash or array reference into a JSON object. Unless you |
|
|
571 | provide your own JSON object, this means it will be encoded to JSON text |
|
|
572 | in UTF-8. |
|
|
573 | |
|
|
574 | JSON objects (and arrays) are self-delimiting, so you can write JSON at |
|
|
575 | one end of a handle and read them at the other end without using any |
|
|
576 | additional framing. |
|
|
577 | |
|
|
578 | The generated JSON text is guaranteed not to contain any newlines: While |
|
|
579 | this module doesn't need delimiters after or between JSON texts to be |
|
|
580 | able to read them, many other languages depend on that. |
|
|
581 | |
|
|
582 | A simple RPC protocol that interoperates easily with others is to send |
|
|
583 | JSON arrays (or objects, although arrays are usually the better choice as |
|
|
584 | they mimic how function argument passing works) and a newline after each |
|
|
585 | JSON text: |
|
|
586 | |
|
|
587 | $handle->push_write (json => ["method", "arg1", "arg2"]); # whatever |
|
|
588 | $handle->push_write ("\012"); |
|
|
589 | |
|
|
590 | An AnyEvent::Handle receiver would simply use the C<json> read type and |
|
|
591 | rely on the fact that the newline will be skipped as leading whitespace: |
|
|
592 | |
|
|
593 | $handle->push_read (json => sub { my $array = $_[1]; ... }); |
|
|
594 | |
|
|
595 | Other languages could read single lines terminated by a newline and pass |
|
|
596 | this line into their JSON decoder of choice. |
|
|
597 | |
|
|
598 | =cut |
|
|
599 | |
|
|
600 | register_write_type json => sub { |
|
|
601 | my ($self, $ref) = @_; |
|
|
602 | |
|
|
603 | require JSON; |
|
|
604 | |
|
|
605 | $self->{json} ? $self->{json}->encode ($ref) |
|
|
606 | : JSON::encode_json ($ref) |
|
|
607 | }; |
|
|
608 | |
|
|
609 | =item storable => $reference |
|
|
610 | |
|
|
611 | Freezes the given reference using L<Storable> and writes it to the |
|
|
612 | handle. Uses the C<nfreeze> format. |
|
|
613 | |
|
|
614 | =cut |
|
|
615 | |
|
|
616 | register_write_type storable => sub { |
|
|
617 | my ($self, $ref) = @_; |
|
|
618 | |
|
|
619 | require Storable; |
|
|
620 | |
|
|
621 | pack "w/a*", Storable::nfreeze ($ref) |
|
|
622 | }; |
|
|
623 | |
|
|
624 | =back |
|
|
625 | |
375 | =item AnyEvent::Handle::register_write_type type => $coderef->($self, @args) |
626 | =item AnyEvent::Handle::register_write_type type => $coderef->($handle, @args) |
376 | |
627 | |
377 | This function (not method) lets you add your own types to C<push_write>. |
628 | This function (not method) lets you add your own types to C<push_write>. |
378 | Whenever the given C<type> is used, C<push_write> will invoke the code |
629 | Whenever the given C<type> is used, C<push_write> will invoke the code |
379 | reference with the handle object and the remaining arguments. |
630 | reference with the handle object and the remaining arguments. |
380 | |
631 | |
… | |
… | |
399 | ways, the "simple" way, using only C<on_read> and the "complex" way, using |
650 | ways, the "simple" way, using only C<on_read> and the "complex" way, using |
400 | a queue. |
651 | a queue. |
401 | |
652 | |
402 | In the simple case, you just install an C<on_read> callback and whenever |
653 | In the simple case, you just install an C<on_read> callback and whenever |
403 | new data arrives, it will be called. You can then remove some data (if |
654 | new data arrives, it will be called. You can then remove some data (if |
404 | enough is there) from the read buffer (C<< $handle->rbuf >>) if you want |
655 | enough is there) from the read buffer (C<< $handle->rbuf >>). Or you cna |
405 | or not. |
656 | leave the data there if you want to accumulate more (e.g. when only a |
|
|
657 | partial message has been received so far). |
406 | |
658 | |
407 | In the more complex case, you want to queue multiple callbacks. In this |
659 | In the more complex case, you want to queue multiple callbacks. In this |
408 | case, AnyEvent::Handle will call the first queued callback each time new |
660 | case, AnyEvent::Handle will call the first queued callback each time new |
409 | data arrives and removes it when it has done its job (see C<push_read>, |
661 | data arrives (also the first time it is queued) and removes it when it has |
410 | below). |
662 | done its job (see C<push_read>, below). |
411 | |
663 | |
412 | This way you can, for example, push three line-reads, followed by reading |
664 | This way you can, for example, push three line-reads, followed by reading |
413 | a chunk of data, and AnyEvent::Handle will execute them in order. |
665 | a chunk of data, and AnyEvent::Handle will execute them in order. |
414 | |
666 | |
415 | Example 1: EPP protocol parser. EPP sends 4 byte length info, followed by |
667 | Example 1: EPP protocol parser. EPP sends 4 byte length info, followed by |
416 | the specified number of bytes which give an XML datagram. |
668 | the specified number of bytes which give an XML datagram. |
417 | |
669 | |
418 | # in the default state, expect some header bytes |
670 | # in the default state, expect some header bytes |
419 | $handle->on_read (sub { |
671 | $handle->on_read (sub { |
420 | # some data is here, now queue the length-header-read (4 octets) |
672 | # some data is here, now queue the length-header-read (4 octets) |
421 | shift->unshift_read_chunk (4, sub { |
673 | shift->unshift_read (chunk => 4, sub { |
422 | # header arrived, decode |
674 | # header arrived, decode |
423 | my $len = unpack "N", $_[1]; |
675 | my $len = unpack "N", $_[1]; |
424 | |
676 | |
425 | # now read the payload |
677 | # now read the payload |
426 | shift->unshift_read_chunk ($len, sub { |
678 | shift->unshift_read (chunk => $len, sub { |
427 | my $xml = $_[1]; |
679 | my $xml = $_[1]; |
428 | # handle xml |
680 | # handle xml |
429 | }); |
681 | }); |
430 | }); |
682 | }); |
431 | }); |
683 | }); |
432 | |
684 | |
433 | Example 2: Implement a client for a protocol that replies either with |
685 | Example 2: Implement a client for a protocol that replies either with "OK" |
434 | "OK" and another line or "ERROR" for one request, and 64 bytes for the |
686 | and another line or "ERROR" for the first request that is sent, and 64 |
435 | second request. Due tot he availability of a full queue, we can just |
687 | bytes for the second request. Due to the availability of a queue, we can |
436 | pipeline sending both requests and manipulate the queue as necessary in |
688 | just pipeline sending both requests and manipulate the queue as necessary |
437 | the callbacks: |
689 | in the callbacks. |
438 | |
690 | |
439 | # request one |
691 | When the first callback is called and sees an "OK" response, it will |
|
|
692 | C<unshift> another line-read. This line-read will be queued I<before> the |
|
|
693 | 64-byte chunk callback. |
|
|
694 | |
|
|
695 | # request one, returns either "OK + extra line" or "ERROR" |
440 | $handle->push_write ("request 1\015\012"); |
696 | $handle->push_write ("request 1\015\012"); |
441 | |
697 | |
442 | # we expect "ERROR" or "OK" as response, so push a line read |
698 | # we expect "ERROR" or "OK" as response, so push a line read |
443 | $handle->push_read_line (sub { |
699 | $handle->push_read (line => sub { |
444 | # if we got an "OK", we have to _prepend_ another line, |
700 | # if we got an "OK", we have to _prepend_ another line, |
445 | # so it will be read before the second request reads its 64 bytes |
701 | # so it will be read before the second request reads its 64 bytes |
446 | # which are already in the queue when this callback is called |
702 | # which are already in the queue when this callback is called |
447 | # we don't do this in case we got an error |
703 | # we don't do this in case we got an error |
448 | if ($_[1] eq "OK") { |
704 | if ($_[1] eq "OK") { |
449 | $_[0]->unshift_read_line (sub { |
705 | $_[0]->unshift_read (line => sub { |
450 | my $response = $_[1]; |
706 | my $response = $_[1]; |
451 | ... |
707 | ... |
452 | }); |
708 | }); |
453 | } |
709 | } |
454 | }); |
710 | }); |
455 | |
711 | |
456 | # request two |
712 | # request two, simply returns 64 octets |
457 | $handle->push_write ("request 2\015\012"); |
713 | $handle->push_write ("request 2\015\012"); |
458 | |
714 | |
459 | # simply read 64 bytes, always |
715 | # simply read 64 bytes, always |
460 | $handle->push_read_chunk (64, sub { |
716 | $handle->push_read (chunk => 64, sub { |
461 | my $response = $_[1]; |
717 | my $response = $_[1]; |
462 | ... |
718 | ... |
463 | }); |
719 | }); |
464 | |
720 | |
465 | =over 4 |
721 | =over 4 |
466 | |
722 | |
467 | =cut |
723 | =cut |
468 | |
724 | |
469 | sub _drain_rbuf { |
725 | sub _drain_rbuf { |
470 | my ($self) = @_; |
726 | my ($self) = @_; |
|
|
727 | |
|
|
728 | local $self->{_in_drain} = 1; |
471 | |
729 | |
472 | if ( |
730 | if ( |
473 | defined $self->{rbuf_max} |
731 | defined $self->{rbuf_max} |
474 | && $self->{rbuf_max} < length $self->{rbuf} |
732 | && $self->{rbuf_max} < length $self->{rbuf} |
475 | ) { |
733 | ) { |
476 | $! = &Errno::ENOSPC; |
734 | return $self->_error (&Errno::ENOSPC, 1); |
477 | $self->error; |
|
|
478 | } |
735 | } |
479 | |
736 | |
480 | return if $self->{in_drain}; |
737 | while () { |
481 | local $self->{in_drain} = 1; |
|
|
482 | |
|
|
483 | while (my $len = length $self->{rbuf}) { |
738 | my $len = length $self->{rbuf}; |
484 | no strict 'refs'; |
739 | |
485 | if (my $cb = shift @{ $self->{queue} }) { |
740 | if (my $cb = shift @{ $self->{_queue} }) { |
486 | unless ($cb->($self)) { |
741 | unless ($cb->($self)) { |
487 | if ($self->{eof}) { |
742 | if ($self->{_eof}) { |
488 | # no progress can be made (not enough data and no data forthcoming) |
743 | # no progress can be made (not enough data and no data forthcoming) |
489 | $! = &Errno::EPIPE; |
744 | $self->_error (&Errno::EPIPE, 1), last; |
490 | $self->error; |
|
|
491 | } |
745 | } |
492 | |
746 | |
493 | unshift @{ $self->{queue} }, $cb; |
747 | unshift @{ $self->{_queue} }, $cb; |
494 | return; |
748 | last; |
495 | } |
749 | } |
496 | } elsif ($self->{on_read}) { |
750 | } elsif ($self->{on_read}) { |
|
|
751 | last unless $len; |
|
|
752 | |
497 | $self->{on_read}($self); |
753 | $self->{on_read}($self); |
498 | |
754 | |
499 | if ( |
755 | if ( |
500 | $self->{eof} # if no further data will arrive |
|
|
501 | && $len == length $self->{rbuf} # and no data has been consumed |
756 | $len == length $self->{rbuf} # if no data has been consumed |
502 | && !@{ $self->{queue} } # and the queue is still empty |
757 | && !@{ $self->{_queue} } # and the queue is still empty |
503 | && $self->{on_read} # and we still want to read data |
758 | && $self->{on_read} # but we still have on_read |
504 | ) { |
759 | ) { |
|
|
760 | # no further data will arrive |
505 | # then no progress can be made |
761 | # so no progress can be made |
506 | $! = &Errno::EPIPE; |
762 | $self->_error (&Errno::EPIPE, 1), last |
507 | $self->error; |
763 | if $self->{_eof}; |
|
|
764 | |
|
|
765 | last; # more data might arrive |
508 | } |
766 | } |
509 | } else { |
767 | } else { |
510 | # read side becomes idle |
768 | # read side becomes idle |
511 | delete $self->{rw}; |
769 | delete $self->{_rw}; |
512 | return; |
770 | last; |
513 | } |
771 | } |
514 | } |
772 | } |
515 | |
773 | |
516 | if ($self->{eof}) { |
774 | if ($self->{_eof}) { |
517 | $self->_shutdown; |
775 | if ($self->{on_eof}) { |
518 | $self->{on_eof}($self) |
776 | $self->{on_eof}($self) |
519 | if $self->{on_eof}; |
777 | } else { |
|
|
778 | $self->_error (0, 1); |
|
|
779 | } |
|
|
780 | } |
|
|
781 | |
|
|
782 | # may need to restart read watcher |
|
|
783 | unless ($self->{_rw}) { |
|
|
784 | $self->start_read |
|
|
785 | if $self->{on_read} || @{ $self->{_queue} }; |
520 | } |
786 | } |
521 | } |
787 | } |
522 | |
788 | |
523 | =item $handle->on_read ($cb) |
789 | =item $handle->on_read ($cb) |
524 | |
790 | |
… | |
… | |
530 | |
796 | |
531 | sub on_read { |
797 | sub on_read { |
532 | my ($self, $cb) = @_; |
798 | my ($self, $cb) = @_; |
533 | |
799 | |
534 | $self->{on_read} = $cb; |
800 | $self->{on_read} = $cb; |
|
|
801 | $self->_drain_rbuf if $cb && !$self->{_in_drain}; |
535 | } |
802 | } |
536 | |
803 | |
537 | =item $handle->rbuf |
804 | =item $handle->rbuf |
538 | |
805 | |
539 | Returns the read buffer (as a modifiable lvalue). |
806 | Returns the read buffer (as a modifiable lvalue). |
… | |
… | |
587 | |
854 | |
588 | $cb = ($RH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_read") |
855 | $cb = ($RH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_read") |
589 | ->($self, $cb, @_); |
856 | ->($self, $cb, @_); |
590 | } |
857 | } |
591 | |
858 | |
592 | push @{ $self->{queue} }, $cb; |
859 | push @{ $self->{_queue} }, $cb; |
593 | $self->_drain_rbuf; |
860 | $self->_drain_rbuf unless $self->{_in_drain}; |
594 | } |
861 | } |
595 | |
862 | |
596 | sub unshift_read { |
863 | sub unshift_read { |
597 | my $self = shift; |
864 | my $self = shift; |
598 | my $cb = pop; |
865 | my $cb = pop; |
… | |
… | |
603 | $cb = ($RH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::unshift_read") |
870 | $cb = ($RH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::unshift_read") |
604 | ->($self, $cb, @_); |
871 | ->($self, $cb, @_); |
605 | } |
872 | } |
606 | |
873 | |
607 | |
874 | |
608 | unshift @{ $self->{queue} }, $cb; |
875 | unshift @{ $self->{_queue} }, $cb; |
609 | $self->_drain_rbuf; |
876 | $self->_drain_rbuf unless $self->{_in_drain}; |
610 | } |
877 | } |
611 | |
878 | |
612 | =item $handle->push_read (type => @args, $cb) |
879 | =item $handle->push_read (type => @args, $cb) |
613 | |
880 | |
614 | =item $handle->unshift_read (type => @args, $cb) |
881 | =item $handle->unshift_read (type => @args, $cb) |
… | |
… | |
620 | Predefined types are (if you have ideas for additional types, feel free to |
887 | Predefined types are (if you have ideas for additional types, feel free to |
621 | drop by and tell us): |
888 | drop by and tell us): |
622 | |
889 | |
623 | =over 4 |
890 | =over 4 |
624 | |
891 | |
625 | =item chunk => $octets, $cb->($self, $data) |
892 | =item chunk => $octets, $cb->($handle, $data) |
626 | |
893 | |
627 | Invoke the callback only once C<$octets> bytes have been read. Pass the |
894 | Invoke the callback only once C<$octets> bytes have been read. Pass the |
628 | data read to the callback. The callback will never be called with less |
895 | data read to the callback. The callback will never be called with less |
629 | data. |
896 | data. |
630 | |
897 | |
… | |
… | |
644 | $cb->($_[0], substr $_[0]{rbuf}, 0, $len, ""); |
911 | $cb->($_[0], substr $_[0]{rbuf}, 0, $len, ""); |
645 | 1 |
912 | 1 |
646 | } |
913 | } |
647 | }; |
914 | }; |
648 | |
915 | |
649 | # compatibility with older API |
|
|
650 | sub push_read_chunk { |
|
|
651 | $_[0]->push_read (chunk => $_[1], $_[2]); |
|
|
652 | } |
|
|
653 | |
|
|
654 | sub unshift_read_chunk { |
|
|
655 | $_[0]->unshift_read (chunk => $_[1], $_[2]); |
|
|
656 | } |
|
|
657 | |
|
|
658 | =item line => [$eol, ]$cb->($self, $line, $eol) |
916 | =item line => [$eol, ]$cb->($handle, $line, $eol) |
659 | |
917 | |
660 | The callback will be called only once a full line (including the end of |
918 | The callback will be called only once a full line (including the end of |
661 | line marker, C<$eol>) has been read. This line (excluding the end of line |
919 | line marker, C<$eol>) has been read. This line (excluding the end of line |
662 | marker) will be passed to the callback as second argument (C<$line>), and |
920 | marker) will be passed to the callback as second argument (C<$line>), and |
663 | the end of line marker as the third argument (C<$eol>). |
921 | the end of line marker as the third argument (C<$eol>). |
… | |
… | |
677 | =cut |
935 | =cut |
678 | |
936 | |
679 | register_read_type line => sub { |
937 | register_read_type line => sub { |
680 | my ($self, $cb, $eol) = @_; |
938 | my ($self, $cb, $eol) = @_; |
681 | |
939 | |
682 | $eol = qr|(\015?\012)| if @_ < 3; |
940 | if (@_ < 3) { |
|
|
941 | # this is more than twice as fast as the generic code below |
|
|
942 | sub { |
|
|
943 | $_[0]{rbuf} =~ s/^([^\015\012]*)(\015?\012)// or return; |
|
|
944 | |
|
|
945 | $cb->($_[0], $1, $2); |
|
|
946 | 1 |
|
|
947 | } |
|
|
948 | } else { |
683 | $eol = quotemeta $eol unless ref $eol; |
949 | $eol = quotemeta $eol unless ref $eol; |
684 | $eol = qr|^(.*?)($eol)|s; |
950 | $eol = qr|^(.*?)($eol)|s; |
685 | |
951 | |
686 | sub { |
952 | sub { |
687 | $_[0]{rbuf} =~ s/$eol// or return; |
953 | $_[0]{rbuf} =~ s/$eol// or return; |
688 | |
954 | |
689 | $cb->($_[0], $1, $2); |
955 | $cb->($_[0], $1, $2); |
|
|
956 | 1 |
690 | 1 |
957 | } |
691 | } |
958 | } |
692 | }; |
959 | }; |
693 | |
960 | |
694 | # compatibility with older API |
|
|
695 | sub push_read_line { |
|
|
696 | my $self = shift; |
|
|
697 | $self->push_read (line => @_); |
|
|
698 | } |
|
|
699 | |
|
|
700 | sub unshift_read_line { |
|
|
701 | my $self = shift; |
|
|
702 | $self->unshift_read (line => @_); |
|
|
703 | } |
|
|
704 | |
|
|
705 | =item netstring => $cb->($string) |
|
|
706 | |
|
|
707 | A netstring (http://cr.yp.to/proto/netstrings.txt, this is not an endorsement). |
|
|
708 | |
|
|
709 | Throws an error with C<$!> set to EBADMSG on format violations. |
|
|
710 | |
|
|
711 | =cut |
|
|
712 | |
|
|
713 | register_read_type netstring => sub { |
|
|
714 | my ($self, $cb) = @_; |
|
|
715 | |
|
|
716 | sub { |
|
|
717 | unless ($_[0]{rbuf} =~ s/^(0|[1-9][0-9]*)://) { |
|
|
718 | if ($_[0]{rbuf} =~ /[^0-9]/) { |
|
|
719 | $! = &Errno::EBADMSG; |
|
|
720 | $self->error; |
|
|
721 | } |
|
|
722 | return; |
|
|
723 | } |
|
|
724 | |
|
|
725 | my $len = $1; |
|
|
726 | |
|
|
727 | $self->unshift_read (chunk => $len, sub { |
|
|
728 | my $string = $_[1]; |
|
|
729 | $_[0]->unshift_read (chunk => 1, sub { |
|
|
730 | if ($_[1] eq ",") { |
|
|
731 | $cb->($_[0], $string); |
|
|
732 | } else { |
|
|
733 | $! = &Errno::EBADMSG; |
|
|
734 | $self->error; |
|
|
735 | } |
|
|
736 | }); |
|
|
737 | }); |
|
|
738 | |
|
|
739 | 1 |
|
|
740 | } |
|
|
741 | }; |
|
|
742 | |
|
|
743 | =item regex => $accept[, $reject[, $skip], $cb->($data) |
961 | =item regex => $accept[, $reject[, $skip], $cb->($handle, $data) |
744 | |
962 | |
745 | Makes a regex match against the regex object C<$accept> and returns |
963 | Makes a regex match against the regex object C<$accept> and returns |
746 | everything up to and including the match. |
964 | everything up to and including the match. |
747 | |
965 | |
748 | Example: read a single line terminated by '\n'. |
966 | Example: read a single line terminated by '\n'. |
… | |
… | |
796 | return 1; |
1014 | return 1; |
797 | } |
1015 | } |
798 | |
1016 | |
799 | # reject |
1017 | # reject |
800 | if ($reject && $$rbuf =~ $reject) { |
1018 | if ($reject && $$rbuf =~ $reject) { |
801 | $! = &Errno::EBADMSG; |
1019 | $self->_error (&Errno::EBADMSG); |
802 | $self->error; |
|
|
803 | } |
1020 | } |
804 | |
1021 | |
805 | # skip |
1022 | # skip |
806 | if ($skip && $$rbuf =~ $skip) { |
1023 | if ($skip && $$rbuf =~ $skip) { |
807 | $data .= substr $$rbuf, 0, $+[0], ""; |
1024 | $data .= substr $$rbuf, 0, $+[0], ""; |
… | |
… | |
809 | |
1026 | |
810 | () |
1027 | () |
811 | } |
1028 | } |
812 | }; |
1029 | }; |
813 | |
1030 | |
|
|
1031 | =item netstring => $cb->($handle, $string) |
|
|
1032 | |
|
|
1033 | A netstring (http://cr.yp.to/proto/netstrings.txt, this is not an endorsement). |
|
|
1034 | |
|
|
1035 | Throws an error with C<$!> set to EBADMSG on format violations. |
|
|
1036 | |
|
|
1037 | =cut |
|
|
1038 | |
|
|
1039 | register_read_type netstring => sub { |
|
|
1040 | my ($self, $cb) = @_; |
|
|
1041 | |
|
|
1042 | sub { |
|
|
1043 | unless ($_[0]{rbuf} =~ s/^(0|[1-9][0-9]*)://) { |
|
|
1044 | if ($_[0]{rbuf} =~ /[^0-9]/) { |
|
|
1045 | $self->_error (&Errno::EBADMSG); |
|
|
1046 | } |
|
|
1047 | return; |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | my $len = $1; |
|
|
1051 | |
|
|
1052 | $self->unshift_read (chunk => $len, sub { |
|
|
1053 | my $string = $_[1]; |
|
|
1054 | $_[0]->unshift_read (chunk => 1, sub { |
|
|
1055 | if ($_[1] eq ",") { |
|
|
1056 | $cb->($_[0], $string); |
|
|
1057 | } else { |
|
|
1058 | $self->_error (&Errno::EBADMSG); |
|
|
1059 | } |
|
|
1060 | }); |
|
|
1061 | }); |
|
|
1062 | |
|
|
1063 | 1 |
|
|
1064 | } |
|
|
1065 | }; |
|
|
1066 | |
|
|
1067 | =item packstring => $format, $cb->($handle, $string) |
|
|
1068 | |
|
|
1069 | An octet string prefixed with an encoded length. The encoding C<$format> |
|
|
1070 | uses the same format as a Perl C<pack> format, but must specify a single |
|
|
1071 | integer only (only one of C<cCsSlLqQiInNvVjJw> is allowed, plus an |
|
|
1072 | optional C<!>, C<< < >> or C<< > >> modifier). |
|
|
1073 | |
|
|
1074 | DNS over TCP uses a prefix of C<n>, EPP uses a prefix of C<N>. |
|
|
1075 | |
|
|
1076 | Example: read a block of data prefixed by its length in BER-encoded |
|
|
1077 | format (very efficient). |
|
|
1078 | |
|
|
1079 | $handle->push_read (packstring => "w", sub { |
|
|
1080 | my ($handle, $data) = @_; |
|
|
1081 | }); |
|
|
1082 | |
|
|
1083 | =cut |
|
|
1084 | |
|
|
1085 | register_read_type packstring => sub { |
|
|
1086 | my ($self, $cb, $format) = @_; |
|
|
1087 | |
|
|
1088 | sub { |
|
|
1089 | # when we can use 5.10 we can use ".", but for 5.8 we use the re-pack method |
|
|
1090 | defined (my $len = eval { unpack $format, $_[0]{rbuf} }) |
|
|
1091 | or return; |
|
|
1092 | |
|
|
1093 | $format = length pack $format, $len; |
|
|
1094 | |
|
|
1095 | # bypass unshift if we already have the remaining chunk |
|
|
1096 | if ($format + $len <= length $_[0]{rbuf}) { |
|
|
1097 | my $data = substr $_[0]{rbuf}, $format, $len; |
|
|
1098 | substr $_[0]{rbuf}, 0, $format + $len, ""; |
|
|
1099 | $cb->($_[0], $data); |
|
|
1100 | } else { |
|
|
1101 | # remove prefix |
|
|
1102 | substr $_[0]{rbuf}, 0, $format, ""; |
|
|
1103 | |
|
|
1104 | # read remaining chunk |
|
|
1105 | $_[0]->unshift_read (chunk => $len, $cb); |
|
|
1106 | } |
|
|
1107 | |
|
|
1108 | 1 |
|
|
1109 | } |
|
|
1110 | }; |
|
|
1111 | |
|
|
1112 | =item json => $cb->($handle, $hash_or_arrayref) |
|
|
1113 | |
|
|
1114 | Reads a JSON object or array, decodes it and passes it to the callback. |
|
|
1115 | |
|
|
1116 | If a C<json> object was passed to the constructor, then that will be used |
|
|
1117 | for the final decode, otherwise it will create a JSON coder expecting UTF-8. |
|
|
1118 | |
|
|
1119 | This read type uses the incremental parser available with JSON version |
|
|
1120 | 2.09 (and JSON::XS version 2.2) and above. You have to provide a |
|
|
1121 | dependency on your own: this module will load the JSON module, but |
|
|
1122 | AnyEvent does not depend on it itself. |
|
|
1123 | |
|
|
1124 | Since JSON texts are fully self-delimiting, the C<json> read and write |
|
|
1125 | types are an ideal simple RPC protocol: just exchange JSON datagrams. See |
|
|
1126 | the C<json> write type description, above, for an actual example. |
|
|
1127 | |
|
|
1128 | =cut |
|
|
1129 | |
|
|
1130 | register_read_type json => sub { |
|
|
1131 | my ($self, $cb) = @_; |
|
|
1132 | |
|
|
1133 | require JSON; |
|
|
1134 | |
|
|
1135 | my $data; |
|
|
1136 | my $rbuf = \$self->{rbuf}; |
|
|
1137 | |
|
|
1138 | my $json = $self->{json} ||= JSON->new->utf8; |
|
|
1139 | |
|
|
1140 | sub { |
|
|
1141 | my $ref = $json->incr_parse ($self->{rbuf}); |
|
|
1142 | |
|
|
1143 | if ($ref) { |
|
|
1144 | $self->{rbuf} = $json->incr_text; |
|
|
1145 | $json->incr_text = ""; |
|
|
1146 | $cb->($self, $ref); |
|
|
1147 | |
|
|
1148 | 1 |
|
|
1149 | } else { |
|
|
1150 | $self->{rbuf} = ""; |
|
|
1151 | () |
|
|
1152 | } |
|
|
1153 | } |
|
|
1154 | }; |
|
|
1155 | |
|
|
1156 | =item storable => $cb->($handle, $ref) |
|
|
1157 | |
|
|
1158 | Deserialises a L<Storable> frozen representation as written by the |
|
|
1159 | C<storable> write type (BER-encoded length prefix followed by nfreeze'd |
|
|
1160 | data). |
|
|
1161 | |
|
|
1162 | Raises C<EBADMSG> error if the data could not be decoded. |
|
|
1163 | |
|
|
1164 | =cut |
|
|
1165 | |
|
|
1166 | register_read_type storable => sub { |
|
|
1167 | my ($self, $cb) = @_; |
|
|
1168 | |
|
|
1169 | require Storable; |
|
|
1170 | |
|
|
1171 | sub { |
|
|
1172 | # when we can use 5.10 we can use ".", but for 5.8 we use the re-pack method |
|
|
1173 | defined (my $len = eval { unpack "w", $_[0]{rbuf} }) |
|
|
1174 | or return; |
|
|
1175 | |
|
|
1176 | my $format = length pack "w", $len; |
|
|
1177 | |
|
|
1178 | # bypass unshift if we already have the remaining chunk |
|
|
1179 | if ($format + $len <= length $_[0]{rbuf}) { |
|
|
1180 | my $data = substr $_[0]{rbuf}, $format, $len; |
|
|
1181 | substr $_[0]{rbuf}, 0, $format + $len, ""; |
|
|
1182 | $cb->($_[0], Storable::thaw ($data)); |
|
|
1183 | } else { |
|
|
1184 | # remove prefix |
|
|
1185 | substr $_[0]{rbuf}, 0, $format, ""; |
|
|
1186 | |
|
|
1187 | # read remaining chunk |
|
|
1188 | $_[0]->unshift_read (chunk => $len, sub { |
|
|
1189 | if (my $ref = eval { Storable::thaw ($_[1]) }) { |
|
|
1190 | $cb->($_[0], $ref); |
|
|
1191 | } else { |
|
|
1192 | $self->_error (&Errno::EBADMSG); |
|
|
1193 | } |
|
|
1194 | }); |
|
|
1195 | } |
|
|
1196 | |
|
|
1197 | 1 |
|
|
1198 | } |
|
|
1199 | }; |
|
|
1200 | |
814 | =back |
1201 | =back |
815 | |
1202 | |
816 | =item AnyEvent::Handle::register_read_type type => $coderef->($self, $cb, @args) |
1203 | =item AnyEvent::Handle::register_read_type type => $coderef->($handle, $cb, @args) |
817 | |
1204 | |
818 | This function (not method) lets you add your own types to C<push_read>. |
1205 | This function (not method) lets you add your own types to C<push_read>. |
819 | |
1206 | |
820 | Whenever the given C<type> is used, C<push_read> will invoke the code |
1207 | Whenever the given C<type> is used, C<push_read> will invoke the code |
821 | reference with the handle object, the callback and the remaining |
1208 | reference with the handle object, the callback and the remaining |
… | |
… | |
823 | |
1210 | |
824 | The code reference is supposed to return a callback (usually a closure) |
1211 | The code reference is supposed to return a callback (usually a closure) |
825 | that works as a plain read callback (see C<< ->push_read ($cb) >>). |
1212 | that works as a plain read callback (see C<< ->push_read ($cb) >>). |
826 | |
1213 | |
827 | It should invoke the passed callback when it is done reading (remember to |
1214 | It should invoke the passed callback when it is done reading (remember to |
828 | pass C<$self> as first argument as all other callbacks do that). |
1215 | pass C<$handle> as first argument as all other callbacks do that). |
829 | |
1216 | |
830 | Note that this is a function, and all types registered this way will be |
1217 | Note that this is a function, and all types registered this way will be |
831 | global, so try to use unique names. |
1218 | global, so try to use unique names. |
832 | |
1219 | |
833 | For examples, see the source of this module (F<perldoc -m AnyEvent::Handle>, |
1220 | For examples, see the source of this module (F<perldoc -m AnyEvent::Handle>, |
… | |
… | |
836 | =item $handle->stop_read |
1223 | =item $handle->stop_read |
837 | |
1224 | |
838 | =item $handle->start_read |
1225 | =item $handle->start_read |
839 | |
1226 | |
840 | In rare cases you actually do not want to read anything from the |
1227 | In rare cases you actually do not want to read anything from the |
841 | socket. In this case you can call C<stop_read>. Neither C<on_read> no |
1228 | socket. In this case you can call C<stop_read>. Neither C<on_read> nor |
842 | any queued callbacks will be executed then. To start reading again, call |
1229 | any queued callbacks will be executed then. To start reading again, call |
843 | C<start_read>. |
1230 | C<start_read>. |
844 | |
1231 | |
|
|
1232 | Note that AnyEvent::Handle will automatically C<start_read> for you when |
|
|
1233 | you change the C<on_read> callback or push/unshift a read callback, and it |
|
|
1234 | will automatically C<stop_read> for you when neither C<on_read> is set nor |
|
|
1235 | there are any read requests in the queue. |
|
|
1236 | |
845 | =cut |
1237 | =cut |
846 | |
1238 | |
847 | sub stop_read { |
1239 | sub stop_read { |
848 | my ($self) = @_; |
1240 | my ($self) = @_; |
849 | |
1241 | |
850 | delete $self->{rw}; |
1242 | delete $self->{_rw}; |
851 | } |
1243 | } |
852 | |
1244 | |
853 | sub start_read { |
1245 | sub start_read { |
854 | my ($self) = @_; |
1246 | my ($self) = @_; |
855 | |
1247 | |
856 | unless ($self->{rw} || $self->{eof}) { |
1248 | unless ($self->{_rw} || $self->{_eof}) { |
857 | Scalar::Util::weaken $self; |
1249 | Scalar::Util::weaken $self; |
858 | |
1250 | |
859 | $self->{rw} = AnyEvent->io (fh => $self->{fh}, poll => "r", cb => sub { |
1251 | $self->{_rw} = AnyEvent->io (fh => $self->{fh}, poll => "r", cb => sub { |
860 | my $rbuf = $self->{filter_r} ? \my $buf : \$self->{rbuf}; |
1252 | my $rbuf = $self->{filter_r} ? \my $buf : \$self->{rbuf}; |
861 | my $len = sysread $self->{fh}, $$rbuf, $self->{read_size} || 8192, length $$rbuf; |
1253 | my $len = sysread $self->{fh}, $$rbuf, $self->{read_size} || 8192, length $$rbuf; |
862 | |
1254 | |
863 | if ($len > 0) { |
1255 | if ($len > 0) { |
|
|
1256 | $self->{_activity} = AnyEvent->now; |
|
|
1257 | |
864 | $self->{filter_r} |
1258 | $self->{filter_r} |
865 | ? $self->{filter_r}->($self, $rbuf) |
1259 | ? $self->{filter_r}($self, $rbuf) |
866 | : $self->_drain_rbuf; |
1260 | : $self->{_in_drain} || $self->_drain_rbuf; |
867 | |
1261 | |
868 | } elsif (defined $len) { |
1262 | } elsif (defined $len) { |
869 | delete $self->{rw}; |
1263 | delete $self->{_rw}; |
870 | $self->{eof} = 1; |
1264 | $self->{_eof} = 1; |
871 | $self->_drain_rbuf; |
1265 | $self->_drain_rbuf unless $self->{_in_drain}; |
872 | |
1266 | |
873 | } elsif ($! != EAGAIN && $! != EINTR && $! != &AnyEvent::Util::WSAWOULDBLOCK) { |
1267 | } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) { |
874 | return $self->error; |
1268 | return $self->_error ($!, 1); |
875 | } |
1269 | } |
876 | }); |
1270 | }); |
877 | } |
1271 | } |
878 | } |
1272 | } |
879 | |
1273 | |
880 | sub _dotls { |
1274 | sub _dotls { |
881 | my ($self) = @_; |
1275 | my ($self) = @_; |
882 | |
1276 | |
|
|
1277 | my $buf; |
|
|
1278 | |
883 | if (length $self->{tls_wbuf}) { |
1279 | if (length $self->{_tls_wbuf}) { |
884 | while ((my $len = Net::SSLeay::write ($self->{tls}, $self->{tls_wbuf})) > 0) { |
1280 | while ((my $len = Net::SSLeay::write ($self->{tls}, $self->{_tls_wbuf})) > 0) { |
885 | substr $self->{tls_wbuf}, 0, $len, ""; |
1281 | substr $self->{_tls_wbuf}, 0, $len, ""; |
886 | } |
1282 | } |
887 | } |
1283 | } |
888 | |
1284 | |
889 | if (defined (my $buf = Net::SSLeay::BIO_read ($self->{tls_wbio}))) { |
1285 | if (length ($buf = Net::SSLeay::BIO_read ($self->{_wbio}))) { |
890 | $self->{wbuf} .= $buf; |
1286 | $self->{wbuf} .= $buf; |
891 | $self->_drain_wbuf; |
1287 | $self->_drain_wbuf; |
892 | } |
1288 | } |
893 | |
1289 | |
894 | while (defined (my $buf = Net::SSLeay::read ($self->{tls}))) { |
1290 | while (defined ($buf = Net::SSLeay::read ($self->{tls}))) { |
|
|
1291 | if (length $buf) { |
895 | $self->{rbuf} .= $buf; |
1292 | $self->{rbuf} .= $buf; |
896 | $self->_drain_rbuf; |
1293 | $self->_drain_rbuf unless $self->{_in_drain}; |
|
|
1294 | } else { |
|
|
1295 | # let's treat SSL-eof as we treat normal EOF |
|
|
1296 | $self->{_eof} = 1; |
|
|
1297 | $self->_shutdown; |
|
|
1298 | return; |
|
|
1299 | } |
897 | } |
1300 | } |
898 | |
1301 | |
899 | my $err = Net::SSLeay::get_error ($self->{tls}, -1); |
1302 | my $err = Net::SSLeay::get_error ($self->{tls}, -1); |
900 | |
1303 | |
901 | if ($err!= Net::SSLeay::ERROR_WANT_READ ()) { |
1304 | if ($err!= Net::SSLeay::ERROR_WANT_READ ()) { |
902 | if ($err == Net::SSLeay::ERROR_SYSCALL ()) { |
1305 | if ($err == Net::SSLeay::ERROR_SYSCALL ()) { |
903 | $self->error; |
1306 | return $self->_error ($!, 1); |
904 | } elsif ($err == Net::SSLeay::ERROR_SSL ()) { |
1307 | } elsif ($err == Net::SSLeay::ERROR_SSL ()) { |
905 | $! = &Errno::EIO; |
1308 | return $self->_error (&Errno::EIO, 1); |
906 | $self->error; |
|
|
907 | } |
1309 | } |
908 | |
1310 | |
909 | # all others are fine for our purposes |
1311 | # all others are fine for our purposes |
910 | } |
1312 | } |
911 | } |
1313 | } |
… | |
… | |
920 | C<"connect">, C<"accept"> or an existing Net::SSLeay object). |
1322 | C<"connect">, C<"accept"> or an existing Net::SSLeay object). |
921 | |
1323 | |
922 | The second argument is the optional C<Net::SSLeay::CTX> object that is |
1324 | The second argument is the optional C<Net::SSLeay::CTX> object that is |
923 | used when AnyEvent::Handle has to create its own TLS connection object. |
1325 | used when AnyEvent::Handle has to create its own TLS connection object. |
924 | |
1326 | |
925 | =cut |
1327 | The TLS connection object will end up in C<< $handle->{tls} >> after this |
|
|
1328 | call and can be used or changed to your liking. Note that the handshake |
|
|
1329 | might have already started when this function returns. |
926 | |
1330 | |
927 | # TODO: maybe document... |
1331 | =cut |
|
|
1332 | |
928 | sub starttls { |
1333 | sub starttls { |
929 | my ($self, $ssl, $ctx) = @_; |
1334 | my ($self, $ssl, $ctx) = @_; |
930 | |
1335 | |
931 | $self->stoptls; |
1336 | $self->stoptls; |
932 | |
1337 | |
… | |
… | |
947 | # http://www.mail-archive.com/openssl-dev@openssl.org/msg22420.html |
1352 | # http://www.mail-archive.com/openssl-dev@openssl.org/msg22420.html |
948 | Net::SSLeay::CTX_set_mode ($self->{tls}, |
1353 | Net::SSLeay::CTX_set_mode ($self->{tls}, |
949 | (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ENABLE_PARTIAL_WRITE () } || 1) |
1354 | (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ENABLE_PARTIAL_WRITE () } || 1) |
950 | | (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ACCEPT_MOVING_WRITE_BUFFER () } || 2)); |
1355 | | (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ACCEPT_MOVING_WRITE_BUFFER () } || 2)); |
951 | |
1356 | |
952 | $self->{tls_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); |
1357 | $self->{_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); |
953 | $self->{tls_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); |
1358 | $self->{_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); |
954 | |
1359 | |
955 | Net::SSLeay::set_bio ($ssl, $self->{tls_rbio}, $self->{tls_wbio}); |
1360 | Net::SSLeay::set_bio ($ssl, $self->{_rbio}, $self->{_wbio}); |
956 | |
1361 | |
957 | $self->{filter_w} = sub { |
1362 | $self->{filter_w} = sub { |
958 | $_[0]{tls_wbuf} .= ${$_[1]}; |
1363 | $_[0]{_tls_wbuf} .= ${$_[1]}; |
959 | &_dotls; |
1364 | &_dotls; |
960 | }; |
1365 | }; |
961 | $self->{filter_r} = sub { |
1366 | $self->{filter_r} = sub { |
962 | Net::SSLeay::BIO_write ($_[0]{tls_rbio}, ${$_[1]}); |
1367 | Net::SSLeay::BIO_write ($_[0]{_rbio}, ${$_[1]}); |
963 | &_dotls; |
1368 | &_dotls; |
964 | }; |
1369 | }; |
965 | } |
1370 | } |
966 | |
1371 | |
967 | =item $handle->stoptls |
1372 | =item $handle->stoptls |
… | |
… | |
973 | |
1378 | |
974 | sub stoptls { |
1379 | sub stoptls { |
975 | my ($self) = @_; |
1380 | my ($self) = @_; |
976 | |
1381 | |
977 | Net::SSLeay::free (delete $self->{tls}) if $self->{tls}; |
1382 | Net::SSLeay::free (delete $self->{tls}) if $self->{tls}; |
|
|
1383 | |
978 | delete $self->{tls_rbio}; |
1384 | delete $self->{_rbio}; |
979 | delete $self->{tls_wbio}; |
1385 | delete $self->{_wbio}; |
980 | delete $self->{tls_wbuf}; |
1386 | delete $self->{_tls_wbuf}; |
981 | delete $self->{filter_r}; |
1387 | delete $self->{filter_r}; |
982 | delete $self->{filter_w}; |
1388 | delete $self->{filter_w}; |
983 | } |
1389 | } |
984 | |
1390 | |
985 | sub DESTROY { |
1391 | sub DESTROY { |
986 | my $self = shift; |
1392 | my $self = shift; |
987 | |
1393 | |
988 | $self->stoptls; |
1394 | $self->stoptls; |
|
|
1395 | |
|
|
1396 | my $linger = exists $self->{linger} ? $self->{linger} : 3600; |
|
|
1397 | |
|
|
1398 | if ($linger && length $self->{wbuf}) { |
|
|
1399 | my $fh = delete $self->{fh}; |
|
|
1400 | my $wbuf = delete $self->{wbuf}; |
|
|
1401 | |
|
|
1402 | my @linger; |
|
|
1403 | |
|
|
1404 | push @linger, AnyEvent->io (fh => $fh, poll => "w", cb => sub { |
|
|
1405 | my $len = syswrite $fh, $wbuf, length $wbuf; |
|
|
1406 | |
|
|
1407 | if ($len > 0) { |
|
|
1408 | substr $wbuf, 0, $len, ""; |
|
|
1409 | } else { |
|
|
1410 | @linger = (); # end |
|
|
1411 | } |
|
|
1412 | }); |
|
|
1413 | push @linger, AnyEvent->timer (after => $linger, cb => sub { |
|
|
1414 | @linger = (); |
|
|
1415 | }); |
|
|
1416 | } |
989 | } |
1417 | } |
990 | |
1418 | |
991 | =item AnyEvent::Handle::TLS_CTX |
1419 | =item AnyEvent::Handle::TLS_CTX |
992 | |
1420 | |
993 | This function creates and returns the Net::SSLeay::CTX object used by |
1421 | This function creates and returns the Net::SSLeay::CTX object used by |
… | |
… | |
1023 | } |
1451 | } |
1024 | } |
1452 | } |
1025 | |
1453 | |
1026 | =back |
1454 | =back |
1027 | |
1455 | |
|
|
1456 | =head1 SUBCLASSING AnyEvent::Handle |
|
|
1457 | |
|
|
1458 | In many cases, you might want to subclass AnyEvent::Handle. |
|
|
1459 | |
|
|
1460 | To make this easier, a given version of AnyEvent::Handle uses these |
|
|
1461 | conventions: |
|
|
1462 | |
|
|
1463 | =over 4 |
|
|
1464 | |
|
|
1465 | =item * all constructor arguments become object members. |
|
|
1466 | |
|
|
1467 | At least initially, when you pass a C<tls>-argument to the constructor it |
|
|
1468 | will end up in C<< $handle->{tls} >>. Those members might be changed or |
|
|
1469 | mutated later on (for example C<tls> will hold the TLS connection object). |
|
|
1470 | |
|
|
1471 | =item * other object member names are prefixed with an C<_>. |
|
|
1472 | |
|
|
1473 | All object members not explicitly documented (internal use) are prefixed |
|
|
1474 | with an underscore character, so the remaining non-C<_>-namespace is free |
|
|
1475 | for use for subclasses. |
|
|
1476 | |
|
|
1477 | =item * all members not documented here and not prefixed with an underscore |
|
|
1478 | are free to use in subclasses. |
|
|
1479 | |
|
|
1480 | Of course, new versions of AnyEvent::Handle may introduce more "public" |
|
|
1481 | member variables, but thats just life, at least it is documented. |
|
|
1482 | |
|
|
1483 | =back |
|
|
1484 | |
1028 | =head1 AUTHOR |
1485 | =head1 AUTHOR |
1029 | |
1486 | |
1030 | Robin Redeker C<< <elmex at ta-sa.org> >>, Marc Lehmann <schmorp@schmorp.de>. |
1487 | Robin Redeker C<< <elmex at ta-sa.org> >>, Marc Lehmann <schmorp@schmorp.de>. |
1031 | |
1488 | |
1032 | =cut |
1489 | =cut |