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.10 by root, Sat May 3 12:17:35 2008 UTC vs.
Revision 1.14 by root, Sat May 17 19:05:51 2008 UTC

43 $cv->wait; 43 $cv->wait;
44 44
45=head1 DESCRIPTION 45=head1 DESCRIPTION
46 46
47This module is a helper module to make it easier to do event-based I/O on 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 48filehandles. For utility functions for doing non-blocking connects and accepts
49non-blocking resolves and connects). 49on sockets see L<AnyEvent::Util>.
50 50
51In the following, when the documentation refers to of "bytes" then this 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 52means characters. As sysread and syswrite are used for all I/O, their
53treatment of characters applies to this module as well. 53treatment of characters applies to this module as well.
54 54
362=cut 362=cut
363 363
364sub _drain_rbuf { 364sub _drain_rbuf {
365 my ($self) = @_; 365 my ($self) = @_;
366 366
367 return if exists $self->{in_drain}; 367 return if $self->{in_drain};
368 local $self->{in_drain} = 1; 368 local $self->{in_drain} = 1;
369 369
370 while (my $len = length $self->{rbuf}) { 370 while (my $len = length $self->{rbuf}) {
371 no strict 'refs'; 371 no strict 'refs';
372 if (my $cb = shift @{ $self->{queue} }) { 372 if (my $cb = shift @{ $self->{queue} }) {
485sub _read_chunk($$) { 485sub _read_chunk($$) {
486 my ($self, $len, $cb) = @_; 486 my ($self, $len, $cb) = @_;
487 487
488 sub { 488 sub {
489 $len <= length $_[0]{rbuf} or return; 489 $len <= length $_[0]{rbuf} or return;
490 $cb->($self, $_[0], substr $_[0]{rbuf}, 0, $len, ""); 490 $cb->($_[0], substr $_[0]{rbuf}, 0, $len, "");
491 1 491 1
492 } 492 }
493} 493}
494 494
495sub push_read_chunk { 495sub push_read_chunk {
531 my $self = shift; 531 my $self = shift;
532 my $cb = pop; 532 my $cb = pop;
533 my $eol = @_ ? shift : qr|(\015?\012)|; 533 my $eol = @_ ? shift : qr|(\015?\012)|;
534 my $pos; 534 my $pos;
535 535
536 $eol = qr|(\Q$eol\E)| unless ref $eol; 536 $eol = quotemeta $eol unless ref $eol;
537 $eol = qr|^(.*?)($eol)|; 537 $eol = qr|^(.*?)($eol)|s;
538 538
539 sub { 539 sub {
540 $_[0]{rbuf} =~ s/$eol// or return; 540 $_[0]{rbuf} =~ s/$eol// or return;
541 541
542 $cb->($self, $1, $2); 542 $cb->($_[0], $1, $2);
543 1 543 1
544 } 544 }
545} 545}
546 546
547sub push_read_line { 547sub push_read_line {
577 577
578 $self->{rw} = AnyEvent->io (fh => $self->{fh}, poll => "r", cb => sub { 578 $self->{rw} = AnyEvent->io (fh => $self->{fh}, poll => "r", cb => sub {
579 my $len = sysread $self->{fh}, $self->{rbuf}, $self->{read_size} || 8192, length $self->{rbuf}; 579 my $len = sysread $self->{fh}, $self->{rbuf}, $self->{read_size} || 8192, length $self->{rbuf};
580 580
581 if ($len > 0) { 581 if ($len > 0) {
582 if (exists $self->{rbuf_max}) { 582 if (defined $self->{rbuf_max}) {
583 if ($self->{rbuf_max} < length $self->{rbuf}) { 583 if ($self->{rbuf_max} < length $self->{rbuf}) {
584 $! = &Errno::ENOSPC; return $self->error; 584 $! = &Errno::ENOSPC; return $self->error;
585 } 585 }
586 } 586 }
587 587

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines