From c6e7de3579258b73aed9ee5f96c4cb25bb335c86 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 16 Jun 2019 06:11:28 +0000 Subject: ds: stop distinguishing event read and write callbacks Having separate read/write callbacks in every class is too confusing to my easily-confused mind. Instead, give every class an "event_step" callback which is easier to wrap my head around. This will make future code to support IO::Socket::SSL-wrapped sockets easier-to-digest, since SSL_write() can require waiting on POLLIN events, and SSL_read() can require waiting on POLLOUT events. --- lib/PublicInbox/DS.pm | 47 +++-------------------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 2f028a36..2b04886a 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -239,21 +239,6 @@ sub RunTimers { return $timeout; } -sub event_step ($) { - my ($self) = @_; - return if $self->{closed}; - - my $wbuf = $self->{wbuf}; - if (@$wbuf) { - $self->event_write; - return if $self->{closed} || scalar(@$wbuf); - } - - # only read more requests if we've drained the write buffer, - # otherwise we can be buffering infinitely w/o backpressure - $self->event_read; -} - ### The epoll-based event loop. Gets installed as EventLoop if IO::Epoll loads ### okay. sub EpollEventLoop { @@ -267,13 +252,11 @@ sub EpollEventLoop { # get up to 1000 events my $evcount = epoll_wait($Epoll, 1000, $timeout, \@events); for ($i=0; $i<$evcount; $i++) { - my $ev = $events[$i]; - # it's possible epoll_wait returned many events, including some at the end # that ones in the front triggered unregister-interest actions. if we # can't find the %sock entry, it's because we're no longer interested # in that event. - event_step($DescriptorMap{$ev->[0]}); + $DescriptorMap{$events[$i]->[0]}->event_step; } return unless PostEventLoop(); } @@ -316,9 +299,7 @@ sub PollEventLoop { # Fetch handles with read events while (@poll) { my ($fd, $state) = splice(@poll, 0, 2); - next unless $state; - - event_step($DescriptorMap{$fd}); + $DescriptorMap{$fd}->event_step if $state; } return unless PostEventLoop(); @@ -345,8 +326,7 @@ sub KQueueEventLoop { } foreach my $kev (@ret) { - my ($fd, $filter, $flags, $fflags) = @$kev; - event_step($DescriptorMap{$fd}); + $DescriptorMap{$kev->[0]}->event_step; } return unless PostEventLoop(); } @@ -647,27 +627,6 @@ sub on_incomplete_write { $self->watch_write(1); } -=head2 (VIRTUAL) C<< $obj->event_read() >> - -Readable event handler. Concrete deriviatives of PublicInbox::DS should -provide an implementation of this. The default implementation is a noop -if called. - -=cut -sub event_read {} # noop - -=head2 C<< $obj->event_write() >> - -Writable event handler. Concrete deriviatives of PublicInbox::DS may wish to -provide an implementation of this. The default implementation calls -C with an C. - -=cut -sub event_write { - my $self = shift; - $self->write(undef); -} - =head2 C<< $obj->watch_read( $boolean ) >> Turn 'readable' event notification on or off. -- cgit v1.2.3-24-ge0c7