user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 1/3] use pipe for git-http-backend output
  2016-02-25  4:02  5% [PATCH 0/3] migrate git-http-backend to async use Eric Wong
@ 2016-02-25  4:02  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-02-25  4:02 UTC (permalink / raw)
  To: meta

This allows us to stream the output to the client without buffering
everything up-front.  Next, we'll let Danga::Socket (or AE in the
future) wait for readability.
---
 lib/PublicInbox/GitHTTPBackend.pm | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index 562c290..cba025e 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -132,9 +132,9 @@ sub serve_smart {
 	my $buf;
 	my $in;
 	my $err = $env->{'psgi.errors'};
-	if (fileno($input) >= 0) { # FIXME untested
+	if (fileno($input) >= 0) {
 		$in = $input;
-	} else {
+	} else { # FIXME untested
 		$in = IO::File->new_tmpfile;
 		while (1) {
 			my $r = $input->read($buf, 8192);
@@ -148,7 +148,11 @@ sub serve_smart {
 		$in->flush;
 		$in->sysseek(0, SEEK_SET);
 	}
-	my $out = IO::File->new_tmpfile;
+	my ($rpipe, $wpipe);
+	unless (pipe($rpipe, $wpipe)) {
+		$err->print('error creating pipe', $!, "\n");
+		return r(500);
+	}
 	my $pid = fork; # TODO: vfork under Linux...
 	unless (defined $pid) {
 		$err->print('error forking: ', $!, "\n");
@@ -170,22 +174,17 @@ sub serve_smart {
 		$ENV{GIT_HTTP_EXPORT_ALL} = '1';
 		$ENV{PATH_TRANSLATED} = "$git->{git_dir}/$path";
 		dup2(fileno($in), 0) or die "redirect stdin failed: $!\n";
-		dup2(fileno($out), 1) or die "redirect stdout failed: $!\n";
+		dup2(fileno($wpipe), 1) or die "redirect stdout failed: $!\n";
 		my @cmd = qw(git http-backend);
 		exec(@cmd) or die 'exec `' . join(' ', @cmd). "' failed: $!\n";
 	}
-
-	if (waitpid($pid, 0) != $pid) {
-		$err->print("git http-backend ($git->{git_dir}): ", $?, "\n");
-		return r(500);
-	}
+	$wpipe = undef;
 	$in = undef;
-	$out->seek(0, SEEK_SET);
 	my @h;
 	my $code = 200;
 	{
 		local $/ = "\r\n";
-		while (defined(my $line = <$out>)) {
+		while (defined(my $line = <$rpipe>)) {
 			if ($line =~ /\AStatus:\s*(\d+)/) {
 				$code = $1;
 			} else {
@@ -200,7 +199,7 @@ sub serve_smart {
 		my ($cb) = @_;
 		my $fh = $cb->([ $code, \@h ]);
 		while (1) {
-			my $r = $out->read($buf, 8192);
+			my $r = sysread($rpipe, $buf, 8192);
 			die "$!\n" unless defined $r;
 			last if ($r == 0);
 			$fh->write($buf);
-- 
EW


^ permalink raw reply related	[relevance 7%]

* [PATCH 0/3] migrate git-http-backend to async use
@ 2016-02-25  4:02  5% Eric Wong
  2016-02-25  4:02  7% ` [PATCH 1/3] use pipe for git-http-backend output Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-02-25  4:02 UTC (permalink / raw)
  To: meta

git-http-backend (and likely other operations) can take a while
before it returns data.  Do not block synchrously on it.

Eric Wong (3):
      use pipe for git-http-backend output
      git-http-backend: start refactoring to use callback
      git-http-backend: start async API for streaming

 lib/PublicInbox/GitHTTPBackend.pm | 90 +++++++++++++++++++++++++--------------
 public-inbox-httpd                | 31 ++++++++++++++
 2 files changed, 88 insertions(+), 33 deletions(-)


^ permalink raw reply	[relevance 5%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-02-25  4:02  5% [PATCH 0/3] migrate git-http-backend to async use Eric Wong
2016-02-25  4:02  7% ` [PATCH 1/3] use pipe for git-http-backend output 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).