diff options
author | Eric Wong <e@80x24.org> | 2016-05-22 00:33:59 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-22 00:34:07 +0000 |
commit | 6b5e35ca6dc6a505d26f129627b5eb7ff8476539 (patch) | |
tree | d294fcfa2049feacbc510456d09a3101a53da7c5 /lib/PublicInbox | |
parent | 231c19b5c925f1fd40910508a17d370352710e8d (diff) | |
download | public-inbox-6b5e35ca6dc6a505d26f129627b5eb7ff8476539.tar.gz |
Sometimes we need to read something to ensure it's a successful response.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/HTTPD/Async.pm | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index ceba738e..8f3a6a09 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -26,7 +26,23 @@ sub event_read { $_[0]->{cb}->() } sub event_hup { $_[0]->{cb}->() } sub event_err { $_[0]->{cb}->() } sub sysread { shift->{sock}->sysread(@_) } -sub getline { $_[0]->{sock}->getline }; + +sub getline { + my ($self) = @_; + die 'getline called without $/ ref' unless ref $/; + while (1) { + my $ret = $self->read(8192); # Danga::Socket::read + return $$ret if defined $ret; + + return unless $!{EAGAIN} || $!{EINTR}; + + # in case of spurious wakeup, hopefully we never hit this + my $vin = ''; + vec($vin, $self->{fd}, 1) = 1; + my $n; + do { $n = select($vin, undef, undef, undef) } until $n; + } +} sub close { my $self = shift; |