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 0/8] another round of HTTP-related fixes
@ 2016-02-29  1:40  7% Eric Wong
  2016-02-29  1:41  5% ` [PATCH 5/8] favor procedural calls for most private functions Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-02-29  1:40 UTC (permalink / raw)
  To: meta

git clone for Smart HTTP now works properly when using Apache2 \o/

Eric Wong (8):
      http: error check for sysseek on input
      http: document event_write usage
      http: avoid needless time2str calls
      distinguish error messages intended for users vs developers
      favor procedural calls for most private functions
      git-http-backend: stricter parsing of CRLF
      spawnpp: use env(1) for mod_perl compatibility
      git-http-backend: fixes for mod_perl

 lib/PublicInbox/Config.pm         |  6 +++---
 lib/PublicInbox/Daemon.pm         | 18 ++++++++----------
 lib/PublicInbox/GitHTTPBackend.pm | 12 ++++++------
 lib/PublicInbox/HTTP.pm           | 40 ++++++++++++++++++++++-----------------
 lib/PublicInbox/NNTP.pm           | 30 ++++++++++++++---------------
 lib/PublicInbox/Spawn.pm          |  3 ++-
 lib/PublicInbox/SpawnPP.pm        |  9 ++-------
 lib/PublicInbox/WWW.pm            |  2 +-
 script/public-inbox-httpd         |  2 +-
 9 files changed, 61 insertions(+), 61 deletions(-)

^ permalink raw reply	[relevance 7%]

* [PATCH 5/8] favor procedural calls for most private functions
  2016-02-29  1:40  7% [PATCH 0/8] another round of HTTP-related fixes Eric Wong
@ 2016-02-29  1:41  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

This makes for better compile-time checking and also helps
document which calls are private for HTTP and NNTP.

While we're at it, use IO::Handle::* functions procedurally,
too, since we know we're working with native glob handles.
---
 lib/PublicInbox/HTTP.pm   | 22 +++++++++++-----------
 lib/PublicInbox/NNTP.pm   | 28 ++++++++++++++--------------
 lib/PublicInbox/Spawn.pm  |  3 ++-
 script/public-inbox-httpd |  2 +-
 4 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 14971f4..aaae7ab 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -68,7 +68,7 @@ sub rbuf_process {
 
 	# We do not support Trailers in chunked requests, for now
 	# (they are rarely-used and git (as of 2.7.2) does not use them)
-	return $self->quit(400) if $r == -1 || $env{HTTP_TRAILER};
+	return quit($self, 400) if $r == -1 || $env{HTTP_TRAILER};
 	return $self->watch_read(1) if $r < 0; # incomplete
 	$self->{rbuf} = substr($self->{rbuf}, $r);
 	my $len = input_prepare($self, \%env);
@@ -90,7 +90,7 @@ sub event_read_input ($) {
 	while ($len > 0) {
 		if ($$rbuf ne '') {
 			my $w = write_in_full($input, $rbuf, $len);
-			return $self->write_err unless $w;
+			return write_err($self) unless $w;
 			$len -= $w;
 			die "BUG: $len < 0 (w=$w)" if $len < 0;
 			if ($len == 0) { # next request may be pipelined
@@ -100,7 +100,7 @@ sub event_read_input ($) {
 			$$rbuf = '';
 		}
 		my $r = sysread($sock, $$rbuf, 8192);
-		return $self->recv_err($r, $len) unless $r;
+		return recv_err($self, $r, $len) unless $r;
 		# continue looping if $r > 0;
 	}
 	app_dispatch($self);
@@ -238,7 +238,7 @@ sub write_err {
 	my $err = $self->{env}->{'psgi.errors'};
 	my $msg = $! || '(zero write)';
 	$err->print("error buffering to input: $msg\n");
-	$self->quit(500);
+	quit($self, 500);
 }
 
 sub recv_err {
@@ -250,7 +250,7 @@ sub recv_err {
 	}
 	my $err = $self->{env}->{'psgi.errors'};
 	$err->print("error reading for input: $! ($len bytes remaining)\n");
-	$self->quit(500);
+	quit($self, 500);
 }
 
 sub write_in_full {
@@ -278,20 +278,20 @@ sub event_read_input_chunked { # unlikely...
 	while (1) { # chunk start
 		if ($len == CHUNK_ZEND) {
 			return app_dispatch($self) if $$rbuf =~ s/\A\r\n//s;
-			return $self->quit(400) if length($$rbuf) > 2;
+			return quit($self, 400) if length($$rbuf) > 2;
 		}
 		if ($len == CHUNK_END) {
 			if ($$rbuf =~ s/\A\r\n//s) {
 				$len = CHUNK_START;
 			} elsif (length($$rbuf) > 2) {
-				return $self->quit(400);
+				return quit($self, 400);
 			}
 		}
 		if ($len == CHUNK_START) {
 			if ($$rbuf =~ s/\A([a-f0-9]+).*?\r\n//i) {
 				$len = hex $1;
 			} elsif (length($$rbuf) > CHUNK_MAX_HDR) {
-				return $self->quit(400);
+				return quit($self, 400);
 			}
 			# will break from loop since $len >= 0
 		}
@@ -299,7 +299,7 @@ sub event_read_input_chunked { # unlikely...
 		if ($len < 0) { # chunk header is trickled, read more
 			my $off = length($$rbuf);
 			my $r = sysread($sock, $$rbuf, 8192, $off);
-			return $self->recv_err($r, $len) unless $r;
+			return recv_err($self, $r, $len) unless $r;
 			# (implicit) goto chunk_start if $r > 0;
 		}
 		$len = CHUNK_ZEND if $len == 0;
@@ -308,7 +308,7 @@ sub event_read_input_chunked { # unlikely...
 		until ($len <= 0) {
 			if ($$rbuf ne '') {
 				my $w = write_in_full($input, $rbuf, $len);
-				return $self->write_err unless $w;
+				return write_err($self) unless $w;
 				$len -= $w;
 				if ($len == 0) {
 					# we may have leftover data to parse
@@ -324,7 +324,7 @@ sub event_read_input_chunked { # unlikely...
 			if ($$rbuf eq '') {
 				# read more of current chunk
 				my $r = sysread($sock, $$rbuf, 8192);
-				return $self->recv_err($r, $len) unless $r;
+				return recv_err($self, $r, $len) unless $r;
 			}
 		}
 	}
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index fbf8f7f..8740377 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -212,7 +212,7 @@ sub cmd_listgroup ($;$) {
 	}
 
 	$self->{ng} or return '412 no newsgroup selected';
-	$self->long_response(0, long_response_limit, sub {
+	long_response($self, 0, long_response_limit, sub {
 		my ($i) = @_;
 		my $nr = $self->{ng}->mm->id_batch($$i, sub {
 			my ($ary) = @_;
@@ -322,7 +322,7 @@ sub cmd_newnews ($$$$;$$) {
 
 	$ts .= '..';
 	my $opts = { asc => 1, limit => 1000, offset => 0 };
-	$self->long_response(0, long_response_limit, sub {
+	long_response($self, 0, long_response_limit, sub {
 		my ($i) = @_;
 		my $srch = $srch[0];
 		my $res = $srch->query($ts, $opts);
@@ -462,7 +462,7 @@ sub set_art {
 
 sub cmd_article ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 1);
+	my $r = art_lookup($self, $art, 1);
 	return $r unless ref $r;
 	my ($n, $mid, $s) = @$r;
 	set_art($self, $art);
@@ -474,7 +474,7 @@ sub cmd_article ($;$) {
 
 sub cmd_head ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 2);
+	my $r = art_lookup($self, $art, 2);
 	return $r unless ref $r;
 	my ($n, $mid, $s) = @$r;
 	set_art($self, $art);
@@ -485,7 +485,7 @@ sub cmd_head ($;$) {
 
 sub cmd_body ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 0);
+	my $r = art_lookup($self, $art, 0);
 	return $r unless ref $r;
 	my ($n, $mid, $s) = @$r;
 	set_art($self, $art);
@@ -495,7 +495,7 @@ sub cmd_body ($;$) {
 
 sub cmd_stat ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 0);
+	my $r = art_lookup($self, $art, 0);
 	return $r unless ref $r;
 	my ($n, $mid, undef) = @$r;
 	set_art($self, $art);
@@ -612,7 +612,7 @@ sub hdr_message_id ($$$) { # optimize XHDR Message-ID [range] for slrnpull.
 		my $mm = $self->{ng}->mm;
 		my ($beg, $end) = @$r;
 		more($self, $xhdr ? r221 : r225);
-		$self->long_response($beg, $end, sub {
+		long_response($self, $beg, $end, sub {
 			my ($i) = @_;
 			my $mid = $mm->mid_for($$i);
 			more($self, "$$i <$mid>") if defined $mid;
@@ -655,7 +655,7 @@ sub hdr_xref ($$$) { # optimize XHDR Xref [range] for rtin
 		my $mm = $ng->mm;
 		my ($beg, $end) = @$r;
 		more($self, $xhdr ? r221 : r225);
-		$self->long_response($beg, $end, sub {
+		long_response($self, $beg, $end, sub {
 			my ($i) = @_;
 			my $mid = $mm->mid_for($$i);
 			more($self, "$$i ".xref($ng, $$i)) if defined $mid;
@@ -686,7 +686,7 @@ sub hdr_searchmsg ($$$$) {
 		my ($beg, $end) = @$r;
 		more($self, $xhdr ? r221 : r225);
 		my $off = 0;
-		$self->long_response($beg, $end, sub {
+		long_response($self, $beg, $end, sub {
 			my ($i) = @_;
 			my $res = $srch->query_xover($beg, $end, $off);
 			my $msgs = $res->{msgs};
@@ -772,7 +772,7 @@ sub cmd_xrover ($;$) {
 	my $mm = $ng->mm;
 	my $srch = $ng->search;
 	more($self, '224 Overview information follows');
-	$self->long_response($beg, $end, sub {
+	long_response($self, $beg, $end, sub {
 		my ($i) = @_;
 		my $mid = $mm->mid_for($$i) or return;
 		my $h = search_header_for($srch, $mid, 'references');
@@ -822,7 +822,7 @@ sub cmd_xover ($;$) {
 	more($self, "224 Overview information follows for $beg to $end");
 	my $srch = $self->{ng}->search;
 	my $off = 0;
-	$self->long_response($beg, $end, sub {
+	long_response($self, $beg, $end, sub {
 		my ($i) = @_;
 		my $res = $srch->query_xover($beg, $end, $off);
 		my $msgs = $res->{msgs};
@@ -896,7 +896,7 @@ sub do_more ($$) {
 			$data = substr($data, $n, $dlen - $n);
 		}
 	}
-	$self->do_write($data);
+	do_write($self, $data);
 }
 
 # callbacks for Danga::Socket
@@ -924,7 +924,7 @@ sub event_read {
 		my $line = $1;
 		my $t0 = now();
 		my $fd = $self->{fd};
-		$r = eval { $self->process_line($line) };
+		$r = eval { process_line($self, $line) };
 		my $d = $self->{long_res} ?
 			" deferred[$fd]" : '';
 		out($self, "[$fd] %s - %0.6f$d", $line, now() - $t0);
@@ -947,7 +947,7 @@ sub watch_read {
 		# another long response.
 		Danga::Socket->AddTimer(0, sub {
 			if (&Danga::Socket::POLLIN & $self->{event_watch}) {
-				$self->event_read;
+				event_read($self);
 			}
 		});
 	}
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 02c5446..23f303f 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -15,6 +15,7 @@ use strict;
 use warnings;
 use base qw(Exporter);
 use Symbol qw(gensym);
+use IO::Handle;
 use PublicInbox::ProcessPipe;
 our @EXPORT_OK = qw/which spawn popen_rd/;
 
@@ -168,7 +169,7 @@ sub popen_rd {
 	pipe(my ($r, $w)) or die "pipe: $!\n";
 	$opts ||= {};
 	my $blocking = $opts->{Blocking};
-	$r->blocking($blocking) if defined $blocking;
+	IO::Handle::blocking($r, $blocking) if defined $blocking;
 	$opts->{1} = fileno($w);
 	my $pid = spawn($cmd, $env, $opts);
 	return ($r, $pid) if wantarray;
diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index 19315bb..f1a5d79 100755
--- a/script/public-inbox-httpd
+++ b/script/public-inbox-httpd
@@ -68,7 +68,7 @@ use fields qw(cb);
 sub new {
 	my ($class, $io, $cb) = @_;
 	my $self = fields::new($class);
-	$io->blocking(0);
+	IO::Handle::blocking($io, 0);
 	$self->SUPER::new($io);
 	$self->{cb} = $cb;
 	$self->watch_read(1);
-- 
EW


^ permalink raw reply related	[relevance 5%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-02-29  1:40  7% [PATCH 0/8] another round of HTTP-related fixes Eric Wong
2016-02-29  1:41  5% ` [PATCH 5/8] favor procedural calls for most private functions 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).