* [PATCH] http: async getline supports push_back_read
@ 2016-05-22 0:33 7% Eric Wong
0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-05-22 0:33 UTC (permalink / raw)
To: meta
Sometimes we need to read something to ensure it's a successful
response.
---
lib/PublicInbox/HTTPD/Async.pm | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index ceba738..8f3a6a0 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;
--
2.8.0.rc2.38.gfdf5e7f
^ permalink raw reply related [relevance 7%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-05-22 0:33 7% [PATCH] http: async getline supports push_back_read Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).