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

Comparing Coro/Coro/Handle.pm (file contents):
Revision 1.37 by root, Sun May 25 01:32:15 2008 UTC vs.
Revision 1.38 by root, Sun May 25 03:05:42 2008 UTC

38 38
39no warnings; 39no warnings;
40use strict; 40use strict;
41 41
42use Carp (); 42use Carp ();
43use Errno qw(EAGAIN EINTR); 43use Errno qw(EAGAIN EINTR EINPROGRESS);
44 44
45use AnyEvent::Util qw(WSAEAGAIN); 45use AnyEvent::Util qw(WSAWOULDBLOCK WSAEINPROGRESS);
46 46
47use base 'Exporter'; 47use base 'Exporter';
48 48
49our $VERSION = 4.6; 49our $VERSION = 4.72;
50our @EXPORT = qw(unblock); 50our @EXPORT = qw(unblock);
51 51
52=item $fh = new_from_fh Coro::Handle $fhandle [, arg => value...] 52=item $fh = new_from_fh Coro::Handle $fhandle [, arg => value...]
53 53
54Create a new non-blocking io-handle using the given 54Create a new non-blocking io-handle using the given
140Do the same thing as the perl builtins or IO::Socket methods (but return 140Do the same thing as the perl builtins or IO::Socket methods (but return
141true on EINPROGRESS). Remember that these must be method calls. 141true on EINPROGRESS). Remember that these must be method calls.
142 142
143=cut 143=cut
144 144
145sub connect { connect tied(${$_[0]})->[0], $_[1] or $! == Errno::EINPROGRESS } 145sub connect { connect tied(${$_[0]})->[0], $_[1] or $! == EINPROGRESS or $! == WSAEINPROGRESS }
146sub bind { bind tied(${$_[0]})->[0], $_[1] } 146sub bind { bind tied(${$_[0]})->[0], $_[1] }
147sub listen { listen tied(${$_[0]})->[0], $_[1] } 147sub listen { listen tied(${$_[0]})->[0], $_[1] }
148sub getsockopt { getsockopt tied(${$_[0]})->[0], $_[1], $_[2] } 148sub getsockopt { getsockopt tied(${$_[0]})->[0], $_[1], $_[2] }
149sub setsockopt { setsockopt tied(${$_[0]})->[0], $_[1], $_[2], $_[3] } 149sub setsockopt { setsockopt tied(${$_[0]})->[0], $_[1], $_[2], $_[3] }
150sub send { send tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } 150sub send { send tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () }
166 $peername = accept $fh, tied(${$_[0]})->[0] 166 $peername = accept $fh, tied(${$_[0]})->[0]
167 and return wantarray 167 and return wantarray
168 ? ($_[0]->new_from_fh($fh), $peername) 168 ? ($_[0]->new_from_fh($fh), $peername)
169 : $_[0]->new_from_fh($fh); 169 : $_[0]->new_from_fh($fh);
170 170
171 return if $! != EAGAIN && $! != EINTR && $! != WSAEAGAIN; 171 return if $! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK;
172 172
173 $_[0]->readable or return; 173 $_[0]->readable or return;
174 } 174 }
175} 175}
176 176
259 259
260use Carp 'croak'; 260use Carp 'croak';
261use Errno qw(EAGAIN EINTR); 261use Errno qw(EAGAIN EINTR);
262 262
263use AnyEvent (); 263use AnyEvent ();
264use AnyEvent::Util qw(WSAEAGAIN); 264use AnyEvent::Util qw(WSAWOULDBLOCK);
265 265
266# formerly a hash, but we are speed-critical, so try 266# formerly a hash, but we are speed-critical, so try
267# to be faster even if it hurts. 267# to be faster even if it hurts.
268# 268#
269# 0 FH 269# 0 FH
472 if (defined $r) { 472 if (defined $r) {
473 $len -= $r; 473 $len -= $r;
474 $ofs += $r; 474 $ofs += $r;
475 $res += $r; 475 $res += $r;
476 last unless $len; 476 last unless $len;
477 } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEAGAIN) { 477 } elsif ($! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK) {
478 last; 478 last;
479 } 479 }
480 last unless &writable; 480 last unless &writable;
481 } 481 }
482 482
509 if (defined $r) { 509 if (defined $r) {
510 $len -= $r; 510 $len -= $r;
511 $ofs += $r; 511 $ofs += $r;
512 $res += $r; 512 $res += $r;
513 last unless $len && $r; 513 last unless $len && $r;
514 } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEAGAIN) { 514 } elsif ($! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK) {
515 last; 515 last;
516 } 516 }
517 last if $_[0][8] || !&readable; 517 last if $_[0][8] || !&readable;
518 } 518 }
519 519
535 } 535 }
536 536
537 my $r = sysread $_[0][0], $_[0][3], 8192, length $_[0][3]; 537 my $r = sysread $_[0][0], $_[0][3], 8192, length $_[0][3];
538 if (defined $r) { 538 if (defined $r) {
539 return length $_[0][3] ? delete $_[0][3] : undef unless $r; 539 return length $_[0][3] ? delete $_[0][3] : undef unless $r;
540 } elsif (($! != EAGAIN && $! != EINTR && $! != WSAEAGAIN) || !&readable) { 540 } elsif (($! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK) || !&readable) {
541 return length $_[0][3] ? delete $_[0][3] : undef; 541 return length $_[0][3] ? delete $_[0][3] : undef;
542 } 542 }
543 } 543 }
544} 544}
545 545

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines