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 3/5] git-http-backend: simplify dumb serving
  2016-05-22 20:57  6% [PATCH 0/5] a few more HTTP-async-related simplifications Eric Wong
@ 2016-05-22 20:57  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-05-22 20:57 UTC (permalink / raw)
  To: meta

We can rely entirely on getline + close callbacks
and be compatible with 100% of PSGI servers.
---
 lib/PublicInbox/GitHTTPBackend.pm | 66 +++++++++++----------------------------
 1 file changed, 19 insertions(+), 47 deletions(-)

diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index 35c3383..97d96d5 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -92,43 +92,9 @@ sub serve_dumb {
 	# TODO: If-Modified-Since and Last-Modified?
 	open my $in, '<', $f or return r(404);
 	my $len = $size;
-	my $n = 65536; # try to negotiate a big TCP window, first
-	my ($next, $fh);
-	my $cb = sub {
-		$n = $len if $len < $n;
-		my $r = sysread($in, my $buf, $n);
-		if (!defined $r) {
-			err($env, "$f read error: $!");
-			drop_client($env);
-		} elsif ($r <= 0) {
-			err($env, "$f EOF with $len bytes left");
-			drop_client($env);
-		} else {
-			$len -= $r;
-			$fh->write($buf);
-			if ($len == 0) {
-				$fh->close;
-			} elsif ($next) {
-				# avoid recursion in Danga::Socket::write
-				unless ($nextq) {
-					$nextq = [];
-					Danga::Socket->AddTimer(0, *do_next);
-				}
-				# avoid buffering too much in case we have
-				# slow clients:
-				$n = 8192;
-				push @$nextq, $next;
-				return;
-			}
-		}
-		# all done, cleanup references:
-		$fh = $next = undef;
-	};
-
 	my $code = 200;
 	push @h, 'Content-Type', $type;
-	my $range = $env->{HTTP_RANGE};
-	if (defined $range && $range =~ /\bbytes=(\d*)-(\d*)\z/) {
+	if (($env->{HTTP_RANGE} || '') =~ /\bbytes=(\d*)-(\d*)\z/) {
 		($code, $len) = prepare_range($cgi, $in, \@h, $1, $2, $size);
 		if ($code == 416) {
 			push @h, 'Content-Range', "bytes */$size";
@@ -136,18 +102,24 @@ sub serve_dumb {
 		}
 	}
 	push @h, 'Content-Length', $len;
-
-	sub {
-		my ($res) = @_; # Plack callback
-		$fh = $res->([ $code, \@h ]);
-		if (defined $env->{'pi-httpd.async'}) {
-			my $pi_http = $env->{'psgix.io'};
-			$next = sub { $pi_http->write($cb) };
-			$cb->(); # start it off!
-		} else {
-			$cb->() while $fh;
-		}
-	}
+	my $n = 65536;
+	[ $code, \@h, Plack::Util::inline_object(close => sub { close $in },
+		getline => sub {
+			return if $len == 0;
+			$n = $len if $len < $n;
+			my $r = sysread($in, my $buf, $n);
+			if (!defined $r) {
+				err($env, "$f read error: $!");
+			} elsif ($r <= 0) {
+				err($env, "$f EOF with $len bytes left");
+			} else {
+				$len -= $r;
+				$n = 8192;
+				return $buf;
+			}
+			drop_client($env);
+			return;
+		})]
 }
 
 sub prepare_range {

^ permalink raw reply	[relevance 7%]

* [PATCH 0/5] a few more HTTP-async-related simplifications
@ 2016-05-22 20:57  6% Eric Wong
  2016-05-22 20:57  7% ` [PATCH 3/5] git-http-backend: simplify dumb serving Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-05-22 20:57 UTC (permalink / raw)
  To: meta

Since we'll be doing more expensive processes in repobrowse,
it's prudent to refactor and commonalize some of this code.
Here's a start...

Eric Wong (5):
      t/spawn.t: additional tests for popen_rd
      git-http-backend: remove process limit
      git-http-backend: simplify dumb serving
      http: rework async_pass support
      git-http-backend: switch to async_pass

 lib/PublicInbox/GitHTTPBackend.pm | 251 ++++++++++++++++----------------------
 lib/PublicInbox/HTTP.pm           |  24 +---
 lib/PublicInbox/HTTPD/Async.pm    |  45 ++++---
 t/spawn.t                         |  10 ++
 4 files changed, 143 insertions(+), 187 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | sort options + mbox downloads above
-- links below jump to the message on this page --
2016-05-22 20:57  6% [PATCH 0/5] a few more HTTP-async-related simplifications Eric Wong
2016-05-22 20:57  7% ` [PATCH 3/5] git-http-backend: simplify dumb serving Eric Wong

Code repositories for project(s) associated with this 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).