Permalink
Browse files

workaround for http://twitter.com/nihen/status/21380295017

  • Loading branch information...
1 parent 8b60814 commit 1c9b1d0788f4ce9ae0755696bc9d5db77f80b283 kazuho committed Aug 17, 2010
Showing with 26 additions and 26 deletions.
  1. +26 −26 lib/Starlet/Server.pm
View
@@ -278,37 +278,37 @@ sub do_io {
unless ($is_write || delete $self->{_is_deferred_accept}) {
goto DO_SELECT;
}
+ DO_READWRITE:
+ # try to do the IO
+ if ($is_write) {
+ $ret = syswrite $sock, $buf, $len, $off
+ and return $ret;
+ } else {
+ $ret = sysread $sock, $$buf, $len, $off
+ and return $ret;
+ }
+ unless ((! defined($ret)
+ && ($! == EINTR || $! == EAGAIN || $! == EWOULDBLOCK))) {
+ return;
+ }
+ # wait for data
+ DO_SELECT:
while (1) {
- # try to do the IO
+ my ($rfd, $wfd);
+ my $efd = '';
+ vec($efd, fileno($sock), 1) = 1;
if ($is_write) {
- $ret = syswrite $sock, $buf, $len, $off
- and return $ret;
+ ($rfd, $wfd) = ('', $efd);
} else {
- $ret = sysread $sock, $$buf, $len, $off
- and return $ret;
- }
- unless ((! defined($ret)
- && ($! == EINTR || $! == EAGAIN || $! == EWOULDBLOCK))) {
- return;
- }
- # wait for data
- DO_SELECT:
- while (1) {
- my ($rfd, $wfd);
- my $efd = '';
- vec($efd, fileno($sock), 1) = 1;
- if ($is_write) {
- ($rfd, $wfd) = ('', $efd);
- } else {
- ($rfd, $wfd) = ($efd, '');
- }
- my $start_at = time;
- my $nfound = select($rfd, $wfd, $efd, $timeout);
- $timeout -= (time - $start_at);
- last if $nfound;
- return if $timeout <= 0;
+ ($rfd, $wfd) = ($efd, '');
}
+ my $start_at = time;
+ my $nfound = select($rfd, $wfd, $efd, $timeout);
+ $timeout -= (time - $start_at);
+ last if $nfound;
+ return if $timeout <= 0;
}
+ goto DO_READWRITE;
}
# returns (positive) number of bytes read, or undef if the socket is to be closed

0 comments on commit 1c9b1d0

Please sign in to comment.