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.176 by root, Sun Aug 9 00:20:35 2009 UTC vs.
Revision 1.180 by root, Thu Aug 20 22:58:35 2009 UTC

1=head1 NAME 1=head1 NAME
2 2
3AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent 3AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent
4
5=cut
6
7our $VERSION = 4.92;
8 4
9=head1 SYNOPSIS 5=head1 SYNOPSIS
10 6
11 use AnyEvent; 7 use AnyEvent;
12 use AnyEvent::Handle; 8 use AnyEvent::Handle;
62use Errno qw(EAGAIN EINTR); 58use Errno qw(EAGAIN EINTR);
63 59
64use AnyEvent (); BEGIN { AnyEvent::common_sense } 60use AnyEvent (); BEGIN { AnyEvent::common_sense }
65use AnyEvent::Util qw(WSAEWOULDBLOCK); 61use AnyEvent::Util qw(WSAEWOULDBLOCK);
66 62
63our $VERSION = $AnyEvent::VERSION;
64
67=head1 METHODS 65=head1 METHODS
68 66
69=over 4 67=over 4
70 68
71=item $handle = B<new> AnyEvent::TLS fh => $filehandle, key => value... 69=item $handle = B<new> AnyEvent::TLS fh => $filehandle, key => value...
452 delete $self->{_skip_drain_rbuf}; 450 delete $self->{_skip_drain_rbuf};
453 $self->_start; 451 $self->_start;
454 452
455 $self->{on_connect} 453 $self->{on_connect}
456 and $self->{on_connect}($self, $host, $port, sub { 454 and $self->{on_connect}($self, $host, $port, sub {
457 delete @$self{qw(fh _tw _ww _rw _eof _queue rbuf _wbuf tls _tls_rbuf _tls_wbuf)}; 455 delete @$self{qw(fh _tw _rtw _wtw _ww _rw _eof _queue rbuf _wbuf tls _tls_rbuf _tls_wbuf)};
458 $self->{_skip_drain_rbuf} = 1; 456 $self->{_skip_drain_rbuf} = 1;
459 &$retry; 457 &$retry;
460 }); 458 });
461 459
462 } else { 460 } else {
509 if $self->{on_read} || @{ $self->{_queue} }; 507 if $self->{on_read} || @{ $self->{_queue} };
510 508
511 $self->_drain_wbuf; 509 $self->_drain_wbuf;
512} 510}
513 511
514#sub _shutdown {
515# my ($self) = @_;
516#
517# delete @$self{qw(_tw _rw _ww fh wbuf on_read _queue)};
518# $self->{_eof} = 1; # tell starttls et. al to stop trying
519#
520# &_freetls;
521#}
522
523sub _error { 512sub _error {
524 my ($self, $errno, $fatal, $message) = @_; 513 my ($self, $errno, $fatal, $message) = @_;
525 514
526 $! = $errno; 515 $! = $errno;
527 $message ||= "$!"; 516 $message ||= "$!";
889Other languages could read single lines terminated by a newline and pass 878Other languages could read single lines terminated by a newline and pass
890this line into their JSON decoder of choice. 879this line into their JSON decoder of choice.
891 880
892=cut 881=cut
893 882
883sub json_coder() {
884 eval { require JSON::XS; JSON::XS->new->utf8 }
885 || do { require JSON; JSON->new->utf8 }
886}
887
894register_write_type json => sub { 888register_write_type json => sub {
895 my ($self, $ref) = @_; 889 my ($self, $ref) = @_;
896 890
897 require JSON; 891 my $json = $self->{json} ||= json_coder;
898 892
899 $self->{json} ? $self->{json}->encode ($ref) 893 $json->encode ($ref)
900 : JSON::encode_json ($ref)
901}; 894};
902 895
903=item storable => $reference 896=item storable => $reference
904 897
905Freezes the given reference using L<Storable> and writes it to the 898Freezes the given reference using L<Storable> and writes it to the
1459=cut 1452=cut
1460 1453
1461register_read_type json => sub { 1454register_read_type json => sub {
1462 my ($self, $cb) = @_; 1455 my ($self, $cb) = @_;
1463 1456
1464 my $json = $self->{json} ||= 1457 my $json = $self->{json} ||= json_coder;
1465 eval { require JSON::XS; JSON::XS->new->utf8 }
1466 || do { require JSON; JSON->new->utf8 };
1467 1458
1468 my $data; 1459 my $data;
1469 my $rbuf = \$self->{rbuf}; 1460 my $rbuf = \$self->{rbuf};
1470 1461
1471 sub { 1462 sub {
1745 require Net::SSLeay; 1736 require Net::SSLeay;
1746 1737
1747 $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL (); 1738 $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL ();
1748 $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ (); 1739 $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ ();
1749 1740
1750 $tls = $self->{tls}; 1741 $tls = delete $self->{tls};
1751 $ctx = $self->{tls_ctx}; 1742 $ctx = $self->{tls_ctx};
1752 1743
1753 local $Carp::CarpLevel = 1; # skip ourselves when creating a new context or session 1744 local $Carp::CarpLevel = 1; # skip ourselves when creating a new context or session
1754 1745
1755 if ("HASH" eq ref $ctx) { 1746 if ("HASH" eq ref $ctx) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines