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.31 by root, Sun May 25 00:08:49 2008 UTC vs.
Revision 1.35 by root, Mon May 26 05:46:35 2008 UTC

2 2
3no warnings; 3no warnings;
4use strict; 4use strict;
5 5
6use AnyEvent (); 6use AnyEvent ();
7use AnyEvent::Util (); 7use AnyEvent::Util qw(WSAWOULDBLOCK);
8use Scalar::Util (); 8use Scalar::Util ();
9use Carp (); 9use Carp ();
10use Fcntl (); 10use Fcntl ();
11use Errno qw/EAGAIN EINTR/; 11use Errno qw/EAGAIN EINTR/;
12 12
289 289
290sub _drain_wbuf { 290sub _drain_wbuf {
291 my ($self) = @_; 291 my ($self) = @_;
292 292
293 if (!$self->{ww} && length $self->{wbuf}) { 293 if (!$self->{ww} && length $self->{wbuf}) {
294
294 Scalar::Util::weaken $self; 295 Scalar::Util::weaken $self;
296
295 my $cb = sub { 297 my $cb = sub {
296 my $len = syswrite $self->{fh}, $self->{wbuf}; 298 my $len = syswrite $self->{fh}, $self->{wbuf};
297 299
298 if ($len >= 0) { 300 if ($len >= 0) {
299 substr $self->{wbuf}, 0, $len, ""; 301 substr $self->{wbuf}, 0, $len, "";
301 $self->{on_drain}($self) 303 $self->{on_drain}($self)
302 if $self->{low_water_mark} >= length $self->{wbuf} 304 if $self->{low_water_mark} >= length $self->{wbuf}
303 && $self->{on_drain}; 305 && $self->{on_drain};
304 306
305 delete $self->{ww} unless length $self->{wbuf}; 307 delete $self->{ww} unless length $self->{wbuf};
306 } elsif ($! != EAGAIN && $! != EINTR) { 308 } elsif ($! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK) {
307 $self->error; 309 $self->error;
308 } 310 }
309 }; 311 };
310 312
313 # try to write data immediately
314 $cb->();
315
316 # if still data left in wbuf, we need to poll
311 $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb); 317 $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb)
312 318 if length $self->{wbuf};
313 $cb->($self);
314 }; 319 };
315} 320}
316 321
317our %WH; 322our %WH;
318 323
787 } elsif (defined $len) { 792 } elsif (defined $len) {
788 delete $self->{rw}; 793 delete $self->{rw};
789 $self->{eof} = 1; 794 $self->{eof} = 1;
790 $self->_drain_rbuf; 795 $self->_drain_rbuf;
791 796
792 } elsif ($! != EAGAIN && $! != EINTR) { 797 } elsif ($! != EAGAIN && $! != EINTR && $! != &AnyEvent::Util::WSAWOULDBLOCK) {
793 return $self->error; 798 return $self->error;
794 } 799 }
795 }); 800 });
796 } 801 }
797} 802}
863 # but the openssl maintainers basically said: "trust us, it just works". 868 # but the openssl maintainers basically said: "trust us, it just works".
864 # (unfortunately, we have to hardcode constants because the abysmally misdesigned 869 # (unfortunately, we have to hardcode constants because the abysmally misdesigned
865 # and mismaintained ssleay-module doesn't even offer them). 870 # and mismaintained ssleay-module doesn't even offer them).
866 # http://www.mail-archive.com/openssl-dev@openssl.org/msg22420.html 871 # http://www.mail-archive.com/openssl-dev@openssl.org/msg22420.html
867 Net::SSLeay::CTX_set_mode ($self->{tls}, 872 Net::SSLeay::CTX_set_mode ($self->{tls},
868 (eval { Net::SSLeay::MODE_ENABLE_PARTIAL_WRITE () } || 1) 873 (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ENABLE_PARTIAL_WRITE () } || 1)
869 | (eval { Net::SSLeay::MODE_ACCEPT_MOVING_WRITE_BUFFER () } || 2)); 874 | (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ACCEPT_MOVING_WRITE_BUFFER () } || 2));
870 875
871 $self->{tls_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); 876 $self->{tls_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ());
872 $self->{tls_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); 877 $self->{tls_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ());
873 878
874 Net::SSLeay::set_bio ($ssl, $self->{tls_rbio}, $self->{tls_wbio}); 879 Net::SSLeay::set_bio ($ssl, $self->{tls_rbio}, $self->{tls_wbio});

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines