ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.1 by elmex, Sun Apr 27 16:56:17 2008 UTC vs.
Revision 1.9 by root, Fri May 2 16:07:46 2008 UTC

1package AnyEvent::Handle; 1package AnyEvent::Handle;
2 2
3use warnings; 3no warnings;
4use strict; 4use strict;
5 5
6use AnyEvent; 6use AnyEvent ();
7use IO::Handle; 7use AnyEvent::Util ();
8use Scalar::Util ();
9use Carp ();
10use Fcntl ();
8use Errno qw/EAGAIN EINTR/; 11use Errno qw/EAGAIN EINTR/;
9 12
10=head1 NAME 13=head1 NAME
11 14
12AnyEvent::Handle - non-blocking I/O on filehandles via AnyEvent 15AnyEvent::Handle - non-blocking I/O on filehandles via AnyEvent
13 16
14=head1 VERSION
15
16Version 0.01
17
18=cut 17=cut
19 18
20our $VERSION = '0.01'; 19our $VERSION = '0.02';
21 20
22=head1 SYNOPSIS 21=head1 SYNOPSIS
23 22
24 use AnyEvent; 23 use AnyEvent;
25 use AnyEvent::Handle; 24 use AnyEvent::Handle;
26 25
27 my $cv = AnyEvent->condvar; 26 my $cv = AnyEvent->condvar;
28 27
29 my $ae_fh = AnyEvent::Handle->new (fh => \*STDIN); 28 my $ae_fh = AnyEvent::Handle->new (fh => \*STDIN);
30 29
30 #TODO
31
32 # or use the constructor to pass the callback:
33
34 my $ae_fh2 =
35 AnyEvent::Handle->new (
36 fh => \*STDIN,
37 on_eof => sub {
38 $cv->broadcast;
39 },
40 #TODO
41 );
42
43 $cv->wait;
44
45=head1 DESCRIPTION
46
47This module is a helper module to make it easier to do event-based I/O on
48filehandles (and sockets, see L<AnyEvent::Socket> for an easy way to make
49non-blocking resolves and connects).
50
51In the following, when the documentation refers to of "bytes" then this
52means characters. As sysread and syswrite are used for all I/O, their
53treatment of characters applies to this module as well.
54
55All callbacks will be invoked with the handle object as their first
56argument.
57
58=head1 METHODS
59
60=over 4
61
62=item B<new (%args)>
63
64The constructor supports these arguments (all as key => value pairs).
65
66=over 4
67
68=item fh => $filehandle [MANDATORY]
69
70The filehandle this L<AnyEvent::Handle> object will operate on.
71
72NOTE: The filehandle will be set to non-blocking (using
73AnyEvent::Util::fh_nonblocking).
74
75=item on_error => $cb->($self) [MANDATORY]
76
77This is the fatal error callback, that is called when a fatal error ocurs,
78such as not being able to resolve the hostname, failure to connect or a
79read error.
80
81The object will not be in a usable state when this callback has been
82called.
83
84On callback entrance, the value of C<$!> contains the opertaing system
85error (or C<ENOSPC> or C<EPIPE>).
86
87=item on_eof => $cb->($self) [MANDATORY]
88
89Set the callback to be called on EOF.
90
91=item on_read => $cb->($self)
92
93This sets the default read callback, which is called when data arrives
94and no read request is in the queue. If the read callback is C<undef>
95or has never been set, than AnyEvent::Handle will cease reading from the
96filehandle.
97
98To access (and remove data from) the read buffer, use the C<< ->rbuf >>
99method or acces sthe C<$self->{rbuf}> member directly.
100
101When an EOF condition is detected then AnyEvent::Handle will first try to
102feed all the remaining data to the queued callbacks and C<on_read> before
103calling the C<on_eof> callback. If no progress can be made, then a fatal
104error will be raised (with C<$!> set to C<EPIPE>).
105
106=item on_drain => $cb->()
107
108This sets the callback that is called when the write buffer becomes empty
109(or when the callback is set and the buffer is empty already).
110
111To append to the write buffer, use the C<< ->push_write >> method.
112
113=item rbuf_max => <bytes>
114
115If defined, then a fatal error will be raised (with C<$!> set to C<ENOSPC>)
116when the read buffer ever (strictly) exceeds this size. This is useful to
117avoid denial-of-service attacks.
118
119For example, a server accepting connections from untrusted sources should
120be configured to accept only so-and-so much data that it cannot act on
121(for example, when expecting a line, an attacker could send an unlimited
122amount of data without a callback ever being called as long as the line
123isn't finished).
124
125=item read_size => <bytes>
126
127The default read block size (the amount of bytes this module will try to read
128on each [loop iteration). Default: C<4096>.
129
130=item low_water_mark => <bytes>
131
132Sets the amount of bytes (default: C<0>) that make up an "empty" write
133buffer: If the write reaches this size or gets even samller it is
134considered empty.
135
136=back
137
138=cut
139
140sub new {
141 my $class = shift;
142
143 my $self = bless { @_ }, $class;
144
145 $self->{fh} or Carp::croak "mandatory argument fh is missing";
146
147 AnyEvent::Util::fh_nonblocking $self->{fh}, 1;
148
149 $self->on_error ((delete $self->{on_error}) or Carp::croak "mandatory argument on_error is missing");
150 $self->on_eof ((delete $self->{on_eof} ) or Carp::croak "mandatory argument on_eof is missing");
151
152 $self->on_drain (delete $self->{on_drain}) if $self->{on_drain};
153 $self->on_read (delete $self->{on_read} ) if $self->{on_read};
154
155 $self
156}
157
158sub _shutdown {
159 my ($self) = @_;
160
161 delete $self->{rw};
162 delete $self->{ww};
163 delete $self->{fh};
164}
165
166sub error {
167 my ($self) = @_;
168
169 {
170 local $!;
171 $self->_shutdown;
172 }
173
174 $self->{on_error}($self);
175}
176
177=item $fh = $handle->fh
178
179This method returns the filehandle of the L<AnyEvent::Handle> object.
180
181=cut
182
183sub fh { $_[0]->{fh} }
184
185=item $handle->on_error ($cb)
186
187Replace the current C<on_error> callback (see the C<on_error> constructor argument).
188
189=cut
190
191sub on_error {
192 $_[0]{on_error} = $_[1];
193}
194
195=item $handle->on_eof ($cb)
196
197Replace the current C<on_eof> callback (see the C<on_eof> constructor argument).
198
199=cut
200
201sub on_eof {
202 $_[0]{on_eof} = $_[1];
203}
204
205#############################################################################
206
207=back
208
209=head2 WRITE QUEUE
210
211AnyEvent::Handle manages two queues per handle, one for writing and one
212for reading.
213
214The write queue is very simple: you can add data to its end, and
215AnyEvent::Handle will automatically try to get rid of it for you.
216
217When data could be writtena nd the write buffer is shorter then the low
218water mark, the C<on_drain> callback will be invoked.
219
220=over 4
221
222=item $handle->on_drain ($cb)
223
224Sets the C<on_drain> callback or clears it (see the description of
225C<on_drain> in the constructor).
226
227=cut
228
229sub on_drain {
230 my ($self, $cb) = @_;
231
232 $self->{on_drain} = $cb;
233
234 $cb->($self)
235 if $cb && $self->{low_water_mark} >= length $self->{wbuf};
236}
237
238=item $handle->push_write ($data)
239
240Queues the given scalar to be written. You can push as much data as you
241want (only limited by the available memory), as C<AnyEvent::Handle>
242buffers it independently of the kernel.
243
244=cut
245
246sub push_write {
247 my ($self, $data) = @_;
248
249 $self->{wbuf} .= $data;
250
251 unless ($self->{ww}) {
252 Scalar::Util::weaken $self;
253 my $cb = sub {
254 my $len = syswrite $self->{fh}, $self->{wbuf};
255
256 if ($len > 0) {
257 substr $self->{wbuf}, 0, $len, "";
258
259
260 $self->{on_drain}($self)
261 if $self->{low_water_mark} >= length $self->{wbuf}
262 && $self->{on_drain};
263
264 delete $self->{ww} unless length $self->{wbuf};
265 } elsif ($! != EAGAIN && $! != EINTR) {
266 $self->error;
267 }
268 };
269
270 $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb);
271
272 $cb->($self);
273 };
274}
275
276#############################################################################
277
278=back
279
280=head2 READ QUEUE
281
282AnyEvent::Handle manages two queues per handle, one for writing and one
283for reading.
284
285The read queue is more complex than the write queue. It can be used in two
286ways, the "simple" way, using only C<on_read> and the "complex" way, using
287a queue.
288
289In the simple case, you just install an C<on_read> callback and whenever
290new data arrives, it will be called. You can then remove some data (if
291enough is there) from the read buffer (C<< $handle->rbuf >>) if you want
292or not.
293
294In the more complex case, you want to queue multiple callbacks. In this
295case, AnyEvent::Handle will call the first queued callback each time new
296data arrives and removes it when it has done its job (see C<push_read>,
297below).
298
299This way you can, for example, push three line-reads, followed by reading
300a chunk of data, and AnyEvent::Handle will execute them in order.
301
302Example 1: EPP protocol parser. EPP sends 4 byte length info, followed by
303the specified number of bytes which give an XML datagram.
304
305 # in the default state, expect some header bytes
306 $handle->on_read (sub {
307 # some data is here, now queue the length-header-read (4 octets)
308 shift->unshift_read_chunk (4, sub {
309 # header arrived, decode
310 my $len = unpack "N", $_[1];
311
312 # now read the payload
313 shift->unshift_read_chunk ($len, sub {
314 my $xml = $_[1];
315 # handle xml
316 });
317 });
318 });
319
320Example 2: Implement a client for a protocol that replies either with
321"OK" and another line or "ERROR" for one request, and 64 bytes for the
322second request. Due tot he availability of a full queue, we can just
323pipeline sending both requests and manipulate the queue as necessary in
324the callbacks:
325
326 # request one
327 $handle->push_write ("request 1\015\012");
328
329 # we expect "ERROR" or "OK" as response, so push a line read
31 $ae_fh->readlines (sub { 330 $handle->push_read_line (sub {
32 my ($ae_fh, @lines) = @_; 331 # if we got an "OK", we have to _prepend_ another line,
33 for (@lines) { 332 # so it will be read before the second request reads its 64 bytes
34 chomp; 333 # which are already in the queue when this callback is called
35 print "Line: $_"; 334 # we don't do this in case we got an error
335 if ($_[1] eq "OK") {
336 $_[0]->unshift_read_line (sub {
337 my $response = $_[1];
338 ...
339 });
36 } 340 }
37 $cv->broadcast;
38 }); 341 });
39 342
40 $cv->wait; 343 # request two
344 $handle->push_write ("request 2\015\012");
41 345
42=head1 DESCRIPTION 346 # simply read 64 bytes, always
43 347 $handle->push_read_chunk (64, sub {
44This module is a helper module to make it easier to do non-blocking I/O 348 my $response = $_[1];
45on filehandles (and sockets, see L<AnyEvent::Socket>). 349 ...
46 350 });
47The event loop is provided by L<AnyEvent>.
48
49=head1 METHODS
50 351
51=over 4 352=over 4
52 353
53=item B<new (%args)> 354sub _drain_rbuf {
54
55The constructor has these arguments:
56
57=over 4
58
59=item fh => $filehandle
60
61The filehandle this L<AnyEvent::Handle> object will operate on.
62
63NOTE: The filehandle will be set to non-blocking.
64
65=item read_block_size => $size
66
67The default read block size use for reads via the C<on_read>
68method.
69
70=back
71
72=cut
73
74sub new {
75 my $this = shift;
76 my $class = ref($this) || $this;
77 my $self = { 355 my ($self) = @_;
78 read_block_size => 4096,
79 rbuf => '',
80 @_
81 };
82 bless $self, $class;
83 356
84 $self->{fh}->blocking (0) if $self->{fh}; 357 return if exists $self->{in_drain};
358 local $self->{in_drain} = 1;
85 359
86 if ($self->{on_read}) { 360 while (my $len = length $self->{rbuf}) {
87 $self->on_read ($self->{on_read}); 361 no strict 'refs';
88 362 if (@{ $self->{queue} }) {
363 if ($self->{queue}[0]($self)) {
364 shift @{ $self->{queue} };
365 } elsif ($self->{eof}) {
366 # no progress can be made (not enough data and no data forthcoming)
367 $! = &Errno::EPIPE; return $self->error;
368 } else {
369 return;
370 }
89 } elsif ($self->{on_readline}) { 371 } elsif ($self->{on_read}) {
90 $self->readlines ($self->{on_readline}); 372 $self->{on_read}($self);
373
374 if (
375 $self->{eof} # if no further data will arrive
376 && $len == length $self->{rbuf} # and no data has been consumed
377 && !@{ $self->{queue} } # and the queue is still empty
378 && $self->{on_read} # and we still want to read data
379 ) {
380 # then no progress can be made
381 $! = &Errno::EPIPE; return $self->error;
382 }
383 } else {
384 # read side becomes idle
385 delete $self->{rw};
386 return;
387 }
91 } 388 }
92 389
93 return $self 390 if ($self->{eof}) {
391 $self->_shutdown;
392 $self->{on_eof}($self);
393 }
94} 394}
95 395
96=item B<fh> 396=item $handle->on_read ($cb)
97 397
98This method returns the filehandle of the L<AnyEvent::Handle> object. 398This replaces the currently set C<on_read> callback, or clears it (when
99 399the new callback is C<undef>). See the description of C<on_read> in the
100=cut 400constructor.
101
102sub fh { $_[0]->{fh} }
103
104=item B<on_read ($callback)>
105
106This method installs a C<$callback> that will be called
107when new data arrived. You can access the read buffer via the C<rbuf>
108method (see below).
109
110The first argument of the C<$callback> will be the L<AnyEvent::Handle> object.
111 401
112=cut 402=cut
113 403
114sub on_read { 404sub on_read {
115 my ($self, $cb) = @_; 405 my ($self, $cb) = @_;
406
116 $self->{on_read} = $cb; 407 $self->{on_read} = $cb;
117 408
118 unless (defined $self->{on_read}) { 409 unless ($self->{rw} || $self->{eof}) {
410 Scalar::Util::weaken $self;
411
412 $self->{rw} = AnyEvent->io (fh => $self->{fh}, poll => "r", cb => sub {
413 my $len = sysread $self->{fh}, $self->{rbuf}, $self->{read_size} || 8192, length $self->{rbuf};
414
415 if ($len > 0) {
416 if (exists $self->{rbuf_max}) {
417 if ($self->{rbuf_max} < length $self->{rbuf}) {
418 $! = &Errno::ENOSPC; return $self->error;
419 }
420 }
421
422 } elsif (defined $len) {
423 $self->{eof} = 1;
119 delete $self->{on_read_w}; 424 delete $self->{rw};
120 return; 425
426 } elsif ($! != EAGAIN && $! != EINTR) {
427 return $self->error;
428 }
429
430 $self->_drain_rbuf;
431 });
121 } 432 }
122
123 $self->{on_read_w} =
124 AnyEvent->io (poll => 'r', fh => $self->{fh}, cb => sub {
125 #d# warn "READ:[$self->{read_size}] $self->{read_block_size} : ".length ($self->{rbuf})."\n";
126 my $rbuf_len = length $self->{rbuf};
127 my $l;
128 if (defined $self->{read_size}) {
129 $l = sysread $self->{fh}, $self->{rbuf},
130 ($self->{read_size} - $rbuf_len), $rbuf_len;
131 } else {
132 $l = sysread $self->{fh}, $self->{rbuf}, $self->{read_block_size}, $rbuf_len;
133 }
134 #d# warn "READL $l [$self->{rbuf}]\n";
135
136 if (not defined $l) {
137 return if $! == EAGAIN || $! == EINTR;
138 $self->{on_error}->($self, $!) if $self->{on_error};
139 delete $self->{on_read_w};
140
141 } elsif ($l == 0) {
142 $self->{on_eof}->($self) if $self->{on_eof};
143 delete $self->{on_read_w};
144
145 } else {
146 $self->{on_read}->($self);
147 }
148 });
149} 433}
150 434
151=item B<on_error ($callback)> 435=item $handle->rbuf
152 436
153Whenever a read or write operation resulted in an error the C<$callback> 437Returns the read buffer (as a modifiable lvalue).
154will be called.
155 438
156The first argument of C<$callback> will be the L<AnyEvent::Handle> object itself 439You can access the read buffer directly as the C<< ->{rbuf} >> member, if
157and the second argument will be the value of C<$!>. 440you want.
158 441
159=cut
160
161sub on_error {
162 $_[0]->{on_error} = $_[1];
163}
164
165=item B<on_eof ($callback)>
166
167Installs the C<$callback> that will be called when the end of file is
168encountered in a read operation this C<$callback> will be called. The first
169argument will be the L<AnyEvent::Handle> object itself.
170
171=cut
172
173sub on_eof {
174 $_[0]->{on_eof} = $_[1];
175}
176
177=item B<rbuf>
178
179Returns a reference to the read buffer.
180
181NOTE: The read buffer should only be used or modified if the C<on_read> 442NOTE: The read buffer should only be used or modified if the C<on_read>,
182method is used directly. The C<read> and C<readlines> methods will provide 443C<push_read> or C<unshift_read> methods are used. The other read methods
183the read data to their callbacks. 444automatically manage the read buffer.
184 445
185=cut 446=cut
186 447
187sub rbuf : lvalue { $_[0]->{rbuf} } 448sub rbuf : lvalue {
449 $_[0]{rbuf}
450}
188 451
189=item B<read ($len, $callback)> 452=item $handle->push_read ($cb)
190 453
191Will read exactly C<$len> bytes from the filehandle and call the C<$callback> 454=item $handle->unshift_read ($cb)
192if done so. The first argument to the C<$callback> will be the L<AnyEvent::Handle>
193object itself and the second argument the read data.
194 455
195NOTE: This method will override any callbacks installed via the C<on_read> method. 456Append the given callback to the end of the queue (C<push_read>) or
457prepend it (C<unshift_read>).
196 458
197=cut 459The callback is called each time some additional read data arrives.
198 460
461It must check wether enough data is in the read buffer already.
462
463If not enough data is available, it must return the empty list or a false
464value, in which case it will be called repeatedly until enough data is
465available (or an error condition is detected).
466
467If enough data was available, then the callback must remove all data it is
468interested in (which can be none at all) and return a true value. After returning
469true, it will be removed from the queue.
470
471=cut
472
199sub read { 473sub push_read {
474 my ($self, $cb) = @_;
475
476 push @{ $self->{queue} }, $cb;
477 $self->_drain_rbuf;
478}
479
480sub unshift_read {
481 my ($self, $cb) = @_;
482
483 push @{ $self->{queue} }, $cb;
484 $self->_drain_rbuf;
485}
486
487=item $handle->push_read_chunk ($len, $cb->($self, $data))
488
489=item $handle->unshift_read_chunk ($len, $cb->($self, $data))
490
491Append the given callback to the end of the queue (C<push_read_chunk>) or
492prepend it (C<unshift_read_chunk>).
493
494The callback will be called only once C<$len> bytes have been read, and
495these C<$len> bytes will be passed to the callback.
496
497=cut
498
499sub _read_chunk($$) {
500 my ($len, $cb) = @_;
501
502 sub {
503 $len <= length $_[0]{rbuf} or return;
504 $cb->($_[0], substr $_[0]{rbuf}, 0, $len, "");
505 1
506 }
507}
508
509sub push_read_chunk {
200 my ($self, $len, $cb) = @_; 510 my ($self, $len, $cb) = @_;
201 511
202 $self->{read_cb} = $cb; 512 $self->push_read (_read_chunk $len, $cb);
203 my $old_blk_size = $self->{read_block_size};
204 $self->{read_block_size} = $len;
205
206 $self->on_read (sub {
207 #d# warn "OFOFO $len || ".length($_[0]->{rbuf})."||\n";
208
209 if ($len == length $_[0]->{rbuf}) {
210 $_[0]->{read_block_size} = $old_blk_size;
211 $_[0]->on_read (undef);
212 $_[0]->{read_cb}->($_[0], (substr $self->{rbuf}, 0, $len, ''));
213 }
214 });
215} 513}
216 514
217=item B<readlines ($callback)>
218 515
219=item B<readlines ($sep, $callback)> 516sub unshift_read_chunk {
220
221This method will read lines from the filehandle, seperated by C<$sep> or C<"\n">
222if C<$sep> is not provided. C<$sep> will be used as part of a regex, so it can be
223a regex itself and won't be quoted!
224
225The C<$callback> will be called when at least one
226line could be read. The first argument to the C<$callback> will be the L<AnyEvent::Handle>
227object itself and the rest of the arguments will be the read lines.
228
229NOTE: This method will override any callbacks installed via the C<on_read> method.
230
231=cut
232
233sub readlines {
234 my ($self, $NL, $cb) = @_; 517 my ($self, $len, $cb) = @_;
235 518
236 if (ref $NL) { 519 $self->unshift_read (_read_chunk $len, $cb);
237 $cb = $NL; 520}
238 $NL = "\n"; 521
522=item $handle->push_read_line ([$eol, ]$cb->($self, $line, $eol))
523
524=item $handle->unshift_read_line ([$eol, ]$cb->($self, $line, $eol))
525
526Append the given callback to the end of the queue (C<push_read_line>) or
527prepend it (C<unshift_read_line>).
528
529The callback will be called only once a full line (including the end of
530line marker, C<$eol>) has been read. This line (excluding the end of line
531marker) will be passed to the callback as second argument (C<$line>), and
532the end of line marker as the third argument (C<$eol>).
533
534The end of line marker, C<$eol>, can be either a string, in which case it
535will be interpreted as a fixed record end marker, or it can be a regex
536object (e.g. created by C<qr>), in which case it is interpreted as a
537regular expression.
538
539The end of line marker argument C<$eol> is optional, if it is missing (NOT
540undef), then C<qr|\015?\012|> is used (which is good for most internet
541protocols).
542
543Partial lines at the end of the stream will never be returned, as they are
544not marked by the end of line marker.
545
546=cut
547
548sub _read_line($$) {
549 my $cb = pop;
550 my $eol = @_ ? shift : qr|(\015?\012)|;
551 my $pos;
552
553 $eol = qr|(\Q$eol\E)| unless ref $eol;
554 $eol = qr|^(.*?)($eol)|;
555
556 sub {
557 $_[0]{rbuf} =~ s/$eol// or return;
558
559 $cb->($1, $2);
560 1
239 } 561 }
240
241 $self->{on_readline} = $cb;
242
243 $self->on_read (sub {
244 my @lines;
245 push @lines, $1 while $_[0]->{rbuf} =~ s/(.*)$NL//;
246 $self->{on_readline}->($_[0], @lines);
247 });
248} 562}
249 563
250=item B<write ($data)> 564sub push_read_line {
251
252=item B<write ($callback)>
253
254=item B<write ($data, $callback)>
255
256This method will write C<$data> to the filehandle and call the C<$callback>
257afterwards. If only C<$callback> is provided it will be called when the
258write buffer becomes empty the next time (or immediately if it already is empty).
259
260=cut
261
262sub write {
263 my ($self, $data, $cb) = @_;
264 if (ref $data) { $cb = $data; undef $data }
265 push @{$self->{write_bufs}}, [$data, $cb];
266 $self->_check_writer;
267}
268
269sub _check_writer {
270 my ($self) = @_; 565 my $self = shift;
271 566
272 if ($self->{write_w}) { 567 $self->push_read (&_read_line);
273 unless ($self->{write_cb}) { 568}
274 while (@{$self->{write_bufs}} && not defined $self->{write_bufs}->[0]->[1]) {
275 my $wba = shift @{$self->{write_bufs}};
276 $self->{wbuf} .= $wba->[0];
277 }
278 }
279 return;
280 }
281 569
282 my $wba = shift @{$self->{write_bufs}} 570sub unshift_read_line {
283 or return; 571 my $self = shift;
284 572
285 unless (defined $wba->[0]) { 573 $self->unshift_read (&_read_line);
286 $wba->[1]->($self) if $wba->[1];
287 $self->_check_writer;
288 return;
289 }
290
291 $self->{wbuf} = $wba->[0];
292 $self->{write_cb} = $wba->[1];
293
294 $self->{write_w} =
295 AnyEvent->io (poll => 'w', fh => $self->{fh}, cb => sub {
296 my $l = syswrite $self->{fh}, $self->{wbuf}, length $self->{wbuf};
297
298 if (not defined $l) {
299 return if $! == EAGAIN || $! == EINTR;
300 delete $self->{write_w};
301
302 $self->{on_error}->($self, $!) if $self->{on_error};
303
304 } else {
305 substr $self->{wbuf}, 0, $l, '';
306
307 if (length ($self->{wbuf}) == 0) {
308 $self->{write_cb}->($self) if $self->{write_cb};
309
310 delete $self->{write_w};
311 delete $self->{wbuf};
312 delete $self->{write_cb};
313
314 $self->_check_writer;
315 }
316 }
317 });
318} 574}
319 575
320=back 576=back
321 577
322=head1 AUTHOR 578=head1 AUTHOR
323 579
324Robin Redeker, C<< <elmex at ta-sa.org> >> 580Robin Redeker C<< <elmex at ta-sa.org> >>, Marc Lehmann <schmorp@schmorp.de>.
325
326=head1 BUGS
327
328Please report any bugs or feature requests to
329C<bug-io-anyevent at rt.cpan.org>, or through the web interface at
330L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-AnyEvent>.
331I will be notified, and then you'll automatically be notified of progress on
332your bug as I make changes.
333
334=head1 SUPPORT
335
336You can find documentation for this module with the perldoc command.
337
338 perldoc AnyEvent::Handle
339
340You can also look for information at:
341
342=over 4
343
344=item * AnnoCPAN: Annotated CPAN documentation
345
346L<http://annocpan.org/dist/IO-AnyEvent>
347
348=item * CPAN Ratings
349
350L<http://cpanratings.perl.org/d/IO-AnyEvent>
351
352=item * RT: CPAN's request tracker
353
354L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-AnyEvent>
355
356=item * Search CPAN
357
358L<http://search.cpan.org/dist/IO-AnyEvent>
359
360=back
361
362=head1 ACKNOWLEDGEMENTS
363
364=head1 COPYRIGHT & LICENSE
365
366Copyright 2008 Robin Redeker, all rights reserved.
367
368This program is free software; you can redistribute it and/or modify it
369under the same terms as Perl itself.
370 581
371=cut 582=cut
372 583
3731; # End of AnyEvent::Handle 5841; # End of AnyEvent::Handle

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines