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 6/9] nntp: use sysread to append to existing buffer
  2019-06-10  5:18  5% [PATCH 0/9] ds: Diet Socket Eric Wong
@ 2019-06-10  5:18  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-06-10  5:18 UTC (permalink / raw)
  To: meta

We already do this in PublicInbox::HTTP, as it's superior to
DS::read in this regard.  Initially (when I started writing
NNTP.pm, I wanted to use Danga::Socket's read buffering and
push_back_read (removed in DS) but quickly figured out it wasn't
useful at all for dealing with trickling clients.
---
 lib/PublicInbox/NNTP.pm | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 7729399a..5e66d077 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -954,13 +954,20 @@ sub event_write {
 sub event_read {
 	my ($self) = @_;
 	use constant LINE_MAX => 512; # RFC 977 section 2.3
-
-	if (index($self->{rbuf}, "\n") < 0) {
-		my $buf = $self->read(LINE_MAX) or return $self->close;
-		$self->{rbuf} .= $$buf;
+	my $rbuf = \($self->{rbuf});
+	my $r;
+
+	if (index($$rbuf, "\n") < 0) {
+		my $off = length($$rbuf);
+		$r = sysread($self->{sock}, $$rbuf, LINE_MAX, $off);
+		unless (defined $r) {
+			return if $!{EAGAIN};
+			return $self->close;
+		}
+		return $self->close if $r == 0;
 	}
-	my $r = 1;
-	while ($r > 0 && $self->{rbuf} =~ s/\A[ \t\r\n]*([^\r\n]*)\r?\n//) {
+	$r = 1;
+	while ($r > 0 && $$rbuf =~ s/\A[ \t\r\n]*([^\r\n]*)\r?\n//) {
 		my $line = $1;
 		return $self->close if $line =~ /[[:cntrl:]]/s;
 		my $t0 = now();
@@ -972,7 +979,7 @@ sub event_read {
 	}
 
 	return $self->close if $r < 0;
-	my $len = length($self->{rbuf});
+	my $len = length($$rbuf);
 	return $self->close if ($len >= LINE_MAX);
 	update_idle_time($self);
 }
-- 
EW


^ permalink raw reply related	[relevance 7%]

* [PATCH 0/9] ds: Diet Socket
@ 2019-06-10  5:18  5% Eric Wong
  2019-06-10  5:18  7% ` [PATCH 6/9] nntp: use sysread to append to existing buffer Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2019-06-10  5:18 UTC (permalink / raw)
  To: meta

Getting more aggressive with changes to PublicInbox::DS.

I'm thinking patches 8-9 will be important to make TLS
support easier.

On a side note: while reading the code to IO::KQueue;
I've noticed it doesn't take advantage at all of the
syscall reduction kevent() can potentially provide over
over the use of epoll_ctl+epoll_wait :<

Eric Wong (9):
  ds: simplify write buffer accounting
  ds: cleanup Errno imports and favor constant comparisons
  ds: reduce Errno imports and drop ->close reason
  ds: remove {fd} field
  ds: remove steal_socket method
  nntp: use sysread to append to existing buffer
  ds: remove read method, here, too
  ds: do not distinguish between POLLHUP and POLLERR
  ds: stop caring about event flags set by epoll/poll/kqueue

 lib/PublicInbox/DS.pm          | 235 +++++++++------------------------
 lib/PublicInbox/EvCleanup.pm   |   8 +-
 lib/PublicInbox/HTTP.pm        |  11 +-
 lib/PublicInbox/HTTPD/Async.pm |   4 +-
 lib/PublicInbox/NNTP.pm        |  44 +++---
 5 files changed, 93 insertions(+), 209 deletions(-)

-- 
EW


^ 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 --
2019-06-10  5:18  5% [PATCH 0/9] ds: Diet Socket Eric Wong
2019-06-10  5:18  7% ` [PATCH 6/9] nntp: use sysread to append to existing buffer 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).