… | |
… | |
38 | |
38 | |
39 | no warnings; |
39 | no warnings; |
40 | use strict; |
40 | use strict; |
41 | |
41 | |
42 | use Carp (); |
42 | use Carp (); |
43 | use Errno qw(EAGAIN EINTR); |
43 | use Errno qw(EAGAIN EINTR EINPROGRESS); |
44 | |
44 | |
45 | use AnyEvent::Util qw(WSAEAGAIN); |
45 | use AnyEvent::Util qw(WSAWOULDBLOCK WSAEINPROGRESS); |
46 | |
46 | |
47 | use base 'Exporter'; |
47 | use base 'Exporter'; |
48 | |
48 | |
49 | our $VERSION = 4.6; |
49 | our $VERSION = 4.72; |
50 | our @EXPORT = qw(unblock); |
50 | our @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 | |
54 | Create a new non-blocking io-handle using the given |
54 | Create a new non-blocking io-handle using the given |
… | |
… | |
140 | Do the same thing as the perl builtins or IO::Socket methods (but return |
140 | Do the same thing as the perl builtins or IO::Socket methods (but return |
141 | true on EINPROGRESS). Remember that these must be method calls. |
141 | true on EINPROGRESS). Remember that these must be method calls. |
142 | |
142 | |
143 | =cut |
143 | =cut |
144 | |
144 | |
145 | sub connect { connect tied(${$_[0]})->[0], $_[1] or $! == Errno::EINPROGRESS } |
145 | sub connect { connect tied(${$_[0]})->[0], $_[1] or $! == EINPROGRESS or $! == WSAEINPROGRESS } |
146 | sub bind { bind tied(${$_[0]})->[0], $_[1] } |
146 | sub bind { bind tied(${$_[0]})->[0], $_[1] } |
147 | sub listen { listen tied(${$_[0]})->[0], $_[1] } |
147 | sub listen { listen tied(${$_[0]})->[0], $_[1] } |
148 | sub getsockopt { getsockopt tied(${$_[0]})->[0], $_[1], $_[2] } |
148 | sub getsockopt { getsockopt tied(${$_[0]})->[0], $_[1], $_[2] } |
149 | sub setsockopt { setsockopt tied(${$_[0]})->[0], $_[1], $_[2], $_[3] } |
149 | sub setsockopt { setsockopt tied(${$_[0]})->[0], $_[1], $_[2], $_[3] } |
150 | sub send { send tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } |
150 | sub 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 | |
260 | use Carp 'croak'; |
260 | use Carp 'croak'; |
261 | use Errno qw(EAGAIN EINTR); |
261 | use Errno qw(EAGAIN EINTR); |
262 | |
262 | |
263 | use AnyEvent (); |
263 | use AnyEvent (); |
264 | use AnyEvent::Util qw(WSAEAGAIN); |
264 | use 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 | |