--- AnyEvent/lib/AnyEvent/Handle.pm 2008/05/25 01:10:54 1.32 +++ AnyEvent/lib/AnyEvent/Handle.pm 2008/05/26 05:46:35 1.35 @@ -4,7 +4,7 @@ use strict; use AnyEvent (); -use AnyEvent::Util qw(WSAEAGAIN); +use AnyEvent::Util qw(WSAWOULDBLOCK); use Scalar::Util (); use Carp (); use Fcntl (); @@ -291,7 +291,9 @@ my ($self) = @_; if (!$self->{ww} && length $self->{wbuf}) { + Scalar::Util::weaken $self; + my $cb = sub { my $len = syswrite $self->{fh}, $self->{wbuf}; @@ -303,14 +305,17 @@ && $self->{on_drain}; delete $self->{ww} unless length $self->{wbuf}; - } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEAGAIN) { + } elsif ($! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK) { $self->error; } }; - $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb); + # try to write data immediately + $cb->(); - $cb->($self); + # if still data left in wbuf, we need to poll + $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb) + if length $self->{wbuf}; }; } @@ -789,7 +794,7 @@ $self->{eof} = 1; $self->_drain_rbuf; - } elsif ($! != EAGAIN && $! != EINTR && $! != &AnyEvent::Util::WSAEAGAIN) { + } elsif ($! != EAGAIN && $! != EINTR && $! != &AnyEvent::Util::WSAWOULDBLOCK) { return $self->error; } }); @@ -865,8 +870,8 @@ # and mismaintained ssleay-module doesn't even offer them). # http://www.mail-archive.com/openssl-dev@openssl.org/msg22420.html Net::SSLeay::CTX_set_mode ($self->{tls}, - (eval { Net::SSLeay::MODE_ENABLE_PARTIAL_WRITE () } || 1) - | (eval { Net::SSLeay::MODE_ACCEPT_MOVING_WRITE_BUFFER () } || 2)); + (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ENABLE_PARTIAL_WRITE () } || 1) + | (eval { local $SIG{__DIE__}; Net::SSLeay::MODE_ACCEPT_MOVING_WRITE_BUFFER () } || 2)); $self->{tls_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); $self->{tls_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ());