user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 8/9] ds: do not distinguish between POLLHUP and POLLERR
Date: Mon, 10 Jun 2019 05:18:45 +0000	[thread overview]
Message-ID: <20190610051846.26757-9-e@80x24.org> (raw)
In-Reply-To: <20190610051846.26757-1-e@80x24.org>

In my experience, both are worthless as any normal read/write
call path will be wanting to check errors and deal with them
appropriately; so we can just call event_read, for now.

Eventually, there'll probably be only one callback for dealing
with all in/out/err/hup events to simplify logic, especially w.r.t
TLS socket negotiation.
---
 lib/PublicInbox/DS.pm          | 44 +++++++++++++---------------------
 lib/PublicInbox/HTTP.pm        |  5 ----
 lib/PublicInbox/HTTPD/Async.pm |  2 --
 lib/PublicInbox/NNTP.pm        |  5 ----
 4 files changed, 16 insertions(+), 40 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 78ea7227..9277981b 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -239,6 +239,18 @@ sub RunTimers {
     return $timeout;
 }
 
+# Placeholder callback when we hit POLLERR/POLLHUP or other unrecoverable
+# errors.  Shouldn't be needed in the future.
+sub event_end ($) {
+    my ($self) = @_;
+    return if $self->{closed};
+    $self->{wbuf} = [];
+    $self->{wbuf_off} = 0;
+
+    # we're screwed if a read handler can't handle POLLERR/POLLHUP-type errors
+    $self->event_read;
+}
+
 ### The epoll-based event loop. Gets installed as EventLoop if IO::Epoll loads
 ### okay.
 sub EpollEventLoop {
@@ -268,9 +280,8 @@ sub EpollEventLoop {
             # standard non-profiling codepat
             $pob->event_read   if $state & EPOLLIN && ! $pob->{closed};
             $pob->event_write  if $state & EPOLLOUT && ! $pob->{closed};
-            if ($state & (EPOLLERR|EPOLLHUP)) {
-                $pob->event_err    if $state & EPOLLERR && ! $pob->{closed};
-                $pob->event_hup    if $state & EPOLLHUP && ! $pob->{closed};
+            if ($state & (EPOLLERR|EPOLLHUP) && ! $pob->{closed}) {
+                event_end($pob);
             }
         }
         return unless PostEventLoop();
@@ -320,8 +331,7 @@ sub PollEventLoop {
 
             $pob->event_read   if $state & POLLIN && ! $pob->{closed};
             $pob->event_write  if $state & POLLOUT && ! $pob->{closed};
-            $pob->event_err    if $state & POLLERR && ! $pob->{closed};
-            $pob->event_hup    if $state & POLLHUP && ! $pob->{closed};
+            event_end($pob) if $state & (POLLERR|POLLHUP) && ! $pob->{closed};
         }
 
         return unless PostEventLoop();
@@ -357,11 +367,7 @@ sub KQueueEventLoop {
             $pob->event_read  if $filter == IO::KQueue::EVFILT_READ()  && !$pob->{closed};
             $pob->event_write if $filter == IO::KQueue::EVFILT_WRITE() && !$pob->{closed};
             if ($flags ==  IO::KQueue::EV_EOF() && !$pob->{closed}) {
-                if ($fflags) {
-                    $pob->event_err;
-                } else {
-                    $pob->event_hup;
-                }
+                event_end($pob);
             }
         }
         return unless PostEventLoop();
@@ -672,24 +678,6 @@ called.
 =cut
 sub event_read  { die "Base class event_read called for $_[0]\n"; }
 
-=head2 (VIRTUAL) C<< $obj->event_err() >>
-
-Error event handler. Concrete deriviatives of PublicInbox::DS should
-provide an implementation of this. The default implementation will die if
-called.
-
-=cut
-sub event_err   { die "Base class event_err called for $_[0]\n"; }
-
-=head2 (VIRTUAL) C<< $obj->event_hup() >>
-
-'Hangup' event handler. Concrete deriviatives of PublicInbox::DS should
-provide an implementation of this. The default implementation will die if
-called.
-
-=cut
-sub event_hup   { die "Base class event_hup called for $_[0]\n"; }
-
 =head2 C<< $obj->event_write() >>
 
 Writable event handler. Concrete deriviatives of PublicInbox::DS may wish to
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index fd103251..4fbc34ee 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -466,11 +466,6 @@ sub quit {
 	$self->close;
 }
 
-# callbacks for PublicInbox::DS
-
-sub event_hup { $_[0]->close }
-sub event_err { $_[0]->close }
-
 sub close {
 	my $self = shift;
 	my $forward = $self->{forward};
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index 60701085..4d0c8d5b 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -76,8 +76,6 @@ sub async_pass {
 }
 
 sub event_read { $_[0]->{cb}->(@_) }
-sub event_hup { $_[0]->{cb}->(@_) }
-sub event_err { $_[0]->{cb}->(@_) }
 
 sub close {
 	my $self = shift;
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 5e66d077..85778c44 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -937,11 +937,6 @@ sub do_more ($$) {
 	do_write($self, $data);
 }
 
-# callbacks for PublicInbox::DS
-
-sub event_hup { $_[0]->close }
-sub event_err { $_[0]->close }
-
 sub event_write {
 	my ($self) = @_;
 	update_idle_time($self);
-- 
EW


  parent reply	other threads:[~2019-06-10  5:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10  5:18 [PATCH 0/9] ds: Diet Socket Eric Wong
2019-06-10  5:18 ` [PATCH 1/9] ds: simplify write buffer accounting Eric Wong
2019-06-10  5:18 ` [PATCH 2/9] ds: cleanup Errno imports and favor constant comparisons Eric Wong
2019-06-10  5:18 ` [PATCH 3/9] ds: reduce Errno imports and drop ->close reason Eric Wong
2019-06-10  5:18 ` [PATCH 4/9] ds: remove {fd} field Eric Wong
2019-06-10  5:18 ` [PATCH 5/9] ds: remove steal_socket method Eric Wong
2019-06-10  5:18 ` [PATCH 6/9] nntp: use sysread to append to existing buffer Eric Wong
2019-06-10  5:18 ` [PATCH 7/9] ds: remove read method, here, too Eric Wong
2019-06-10  5:18 ` Eric Wong [this message]
2019-06-10  5:18 ` [PATCH 9/9] ds: stop caring about event flags set by epoll/poll/kqueue Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190610051846.26757-9-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).