| 1 | package FurlX::Coro::HTTP; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use parent qw(Furl::HTTP); | ||
| 6 | use Coro::Select qw(select); | ||
| 7 | use Errno qw(EINTR); | ||
| 8 | |||
| 9 | # just copied from Furl::HTTP | ||
| 10 | sub do_select { | ||
| 11 | my($self, $is_write, $sock, $timeout_at) = @_; | ||
| 12 | # wait for data | ||
| 13 | while (1) { | ||
| 14 | my $timeout = $timeout_at - time; | ||
| 15 | if ($timeout <= 0) { | ||
| 16 | $! = 0; | ||
| 17 | return 0; | ||
| 18 | } | ||
| 19 | my($rfd, $wfd); | ||
| 20 | my $efd = ''; | ||
| 21 | vec($efd, fileno($sock), 1) = 1; | ||
| 22 | if ($is_write) { | ||
| 23 | $wfd = $efd; | ||
| 24 | } else { | ||
| 25 | $rfd = $efd; | ||
| 26 | } | ||
| 27 | my $nfound = select($rfd, $wfd, $efd, $timeout); | ||
| 28 | return 1 if $nfound > 0; | ||
| 29 | return 0 if $nfound == -1 && $! == EINTR && $self->{stop_if}->(); | ||
| 30 | } | ||
| 31 | die 'not reached'; | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; | ||
| 35 | __END__ |