* [PATCH 0/6] ds: less is more
@ 2019-06-03 1:52 Eric Wong
2019-06-03 1:52 ` [PATCH 1/6] ds: drop more unused subs Eric Wong
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 1:52 UTC (permalink / raw)
To: meta
What's better than Free Software? Freedom FROM software!
Eric Wong (6):
ds: drop more unused subs
ds: add a note about planned future changes
ds: drop set_writer_func support
ds: drop checks for invalid descriptors
ds: drop unused EVENT: label in epoll code path
ds: drop write_set_watch field
lib/PublicInbox/DS.pm | 83 +++++-------------------------------
lib/PublicInbox/EvCleanup.pm | 2 +-
2 files changed, 12 insertions(+), 73 deletions(-)
--
EW
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/6] ds: drop more unused subs
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
@ 2019-06-03 1:52 ` Eric Wong
2019-06-03 1:52 ` [PATCH 2/6] ds: add a note about planned future changes Eric Wong
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 1:52 UTC (permalink / raw)
To: meta
ToClose and HaveEpoll are of no use to us and I see no
future use for them, either.
---
lib/PublicInbox/DS.pm | 18 ------------------
lib/PublicInbox/EvCleanup.pm | 2 +-
2 files changed, 1 insertion(+), 19 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 9142f21..89042cf 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -95,24 +95,6 @@ sub Reset {
*EventLoop = *FirstTimeEventLoop;
}
-=head2 C<< CLASS->HaveEpoll() >>
-
-Returns a true value if this class will use IO::Epoll for async IO.
-
-=cut
-sub HaveEpoll {
- _InitPoller();
- return $HaveEpoll;
-}
-
-=head2 C<< CLASS->ToClose() >>
-
-Return the list of sockets that are awaiting close() at the end of the
-current event loop.
-
-=cut
-sub ToClose { return @ToClose; }
-
=head2 C<< CLASS->SetLoopTimeout( $timeout ) >>
Set the loop timeout for the event loop to some value in milliseconds.
diff --git a/lib/PublicInbox/EvCleanup.pm b/lib/PublicInbox/EvCleanup.pm
index b2f8c08..afed24f 100644
--- a/lib/PublicInbox/EvCleanup.pm
+++ b/lib/PublicInbox/EvCleanup.pm
@@ -38,7 +38,7 @@ sub _run_all ($) {
$_->() foreach @$run;
}
-# ensure PublicInbox::DS::ToClose fires after timers fire
+# ensure PublicInbox::DS::ToClose processing after timers fire
sub _asap_close () { $asapq->[1] ||= _asap_timer() }
sub _run_asap () { _run_all($asapq) }
--
EW
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] ds: add a note about planned future changes
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
2019-06-03 1:52 ` [PATCH 1/6] ds: drop more unused subs Eric Wong
@ 2019-06-03 1:52 ` Eric Wong
2019-06-03 1:52 ` [PATCH 3/6] ds: drop set_writer_func support Eric Wong
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 1:52 UTC (permalink / raw)
To: meta
Sometimes I get bored with the email part of this project and
need a distraction :P
---
lib/PublicInbox/DS.pm | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 89042cf..3b0cbe6 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -5,8 +5,14 @@
#
# This is a fork of the (for now) unmaintained Danga::Socket 1.61.
# Unused features will be removed, and updates will be made to take
-# advantage of newer kernels
-
+# advantage of newer kernels.
+#
+# API changes to diverge from Danga::Socket will happen to better
+# accomodate new features and improve scalability. Do not expect
+# this to be a stable API like Danga::Socket.
+# Bugs encountered (and likely fixed) are reported to
+# bug-Danga-Socket@rt.cpan.org and visible at:
+# https://rt.cpan.org/Public/Dist/Display.html?Name=Danga-Socket
package PublicInbox::DS;
use strict;
use bytes;
--
EW
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] ds: drop set_writer_func support
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
2019-06-03 1:52 ` [PATCH 1/6] ds: drop more unused subs Eric Wong
2019-06-03 1:52 ` [PATCH 2/6] ds: add a note about planned future changes Eric Wong
@ 2019-06-03 1:52 ` Eric Wong
2019-06-03 1:52 ` [PATCH 4/6] ds: drop checks for invalid descriptors Eric Wong
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 1:52 UTC (permalink / raw)
To: meta
This is not used by perlbal for OpenSSL support, either;
and it does not appear to be the right layer for doing
write translations anyways (IO::Socket::SSL uses `tie').
---
lib/PublicInbox/DS.pm | 21 ++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 3b0cbe6..b2c4b44 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -33,7 +33,6 @@ use fields ('sock', # underlying socket
'write_set_watch', # bool: true if we internally set watch_write rather than by a subclass
'closed', # bool: socket is closed
'event_watch', # bitmask of events the client is interested in (POLLIN,OUT,etc.)
- 'writer_func', # subref which does writing. must return bytes written (or undef) and set $! on errors
);
use Errno qw(EINPROGRESS EWOULDBLOCK EISCONN ENOTSOCK
@@ -629,18 +628,6 @@ sub sock {
return $self->{sock};
}
-=head2 C<< $obj->set_writer_func( CODEREF ) >>
-
-Sets a function to use instead of C<syswrite()> when writing data to the socket.
-
-=cut
-sub set_writer_func {
- my PublicInbox::DS $self = shift;
- my $wtr = shift;
- Carp::croak("Not a subref") unless !defined $wtr || UNIVERSAL::isa($wtr, "CODE");
- $self->{writer_func} = $wtr;
-}
-
=head2 C<< $obj->write( $data ) >>
Write the specified data to the underlying handle. I<data> may be scalar,
@@ -710,12 +697,8 @@ sub write {
}
my $to_write = $len - $self->{write_buf_offset};
- my $written;
- if (my $wtr = $self->{writer_func}) {
- $written = $wtr->($bref, $to_write, $self->{write_buf_offset});
- } else {
- $written = syswrite($self->{sock}, $$bref, $to_write, $self->{write_buf_offset});
- }
+ my $written = syswrite($self->{sock}, $$bref, $to_write,
+ $self->{write_buf_offset});
if (! defined $written) {
if ($! == EPIPE) {
--
EW
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] ds: drop checks for invalid descriptors
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
` (2 preceding siblings ...)
2019-06-03 1:52 ` [PATCH 3/6] ds: drop set_writer_func support Eric Wong
@ 2019-06-03 1:52 ` Eric Wong
2019-06-03 1:52 ` [PATCH 5/6] ds: drop unused EVENT: label in epoll code path Eric Wong
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 1:52 UTC (permalink / raw)
To: meta
I've used Danga::Socket for well over a decade in various
projects at this point and have never seen the need for it.
If such a bug ever happens; the process should fall over so
it gets fixed ASAP.
---
lib/PublicInbox/DS.pm | 19 -------------------
1 file changed, 19 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index b2c4b44..e11b23d 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -269,16 +269,6 @@ sub EpollEventLoop {
my $code;
my $state = $ev->[1];
- # if we didn't find a Perlbal::Socket subclass for that fd, try other
- # pseudo-registered (above) fds.
- if (! $pob) {
- my $fd = $ev->[0];
- warn "epoll() returned fd $fd w/ state $state for which we have no mapping. removing.\n";
- epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, 0);
- POSIX::close($fd);
- next;
- }
-
DebugLevel >= 1 && $class->DebugMsg("Event: fd=%d (%s), state=%d \@ %s\n",
$ev->[0], ref($pob), $ev->[1], time);
@@ -335,10 +325,6 @@ sub PollEventLoop {
$pob = $DescriptorMap{$fd};
- if (!$pob) {
- next;
- }
-
$pob->event_read if $state & POLLIN && ! $pob->{closed};
$pob->event_write if $state & POLLOUT && ! $pob->{closed};
$pob->event_err if $state & POLLERR && ! $pob->{closed};
@@ -371,11 +357,6 @@ sub KQueueEventLoop {
foreach my $kev (@ret) {
my ($fd, $filter, $flags, $fflags) = @$kev;
my PublicInbox::DS $pob = $DescriptorMap{$fd};
- if (!$pob) {
- warn "kevent() returned fd $fd for which we have no mapping. removing.\n";
- POSIX::close($fd); # close deletes the kevent entry
- next;
- }
DebugLevel >= 1 && $class->DebugMsg("Event: fd=%d (%s), flags=%d \@ %s\n",
$fd, ref($pob), $flags, time);
--
EW
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] ds: drop unused EVENT: label in epoll code path
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
` (3 preceding siblings ...)
2019-06-03 1:52 ` [PATCH 4/6] ds: drop checks for invalid descriptors Eric Wong
@ 2019-06-03 1:52 ` Eric Wong
2019-06-03 1:52 ` [PATCH 6/6] ds: drop write_set_watch field Eric Wong
2019-06-03 9:03 ` [PATCH 7/6] ds: remove PLCMap and per-socket PostLoopCallback Eric Wong
6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 1:52 UTC (permalink / raw)
To: meta
This was never used in Danga::Socket 1.61, either.
---
lib/PublicInbox/DS.pm | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index e11b23d..78210dd 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -257,7 +257,6 @@ sub EpollEventLoop {
# get up to 1000 events
my $evcount = epoll_wait($Epoll, 1000, $timeout, \@events);
- EVENT:
for ($i=0; $i<$evcount; $i++) {
my $ev = $events[$i];
--
EW
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] ds: drop write_set_watch field
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
` (4 preceding siblings ...)
2019-06-03 1:52 ` [PATCH 5/6] ds: drop unused EVENT: label in epoll code path Eric Wong
@ 2019-06-03 1:52 ` Eric Wong
2019-06-03 9:03 ` [PATCH 7/6] ds: remove PLCMap and per-socket PostLoopCallback Eric Wong
6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 1:52 UTC (permalink / raw)
To: meta
We never enable write watches ourselves for HTTP and NNTP,
and only enable the write watch with EvCleanup because it's
an "always on" watch.
---
lib/PublicInbox/DS.pm | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 78210dd..6b04e76 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -30,7 +30,6 @@ use fields ('sock', # underlying socket
'write_buf', # arrayref of scalars, scalarrefs, or coderefs to write
'write_buf_offset', # offset into first array of write_buf to start writing at
'write_buf_size', # total length of data in all write_buf items
- 'write_set_watch', # bool: true if we internally set watch_write rather than by a subclass
'closed', # bool: socket is closed
'event_watch', # bitmask of events the client is interested in (POLLIN,OUT,etc.)
);
@@ -690,7 +689,6 @@ sub write {
push @{$self->{write_buf}}, $bref;
$self->{write_buf_size} += $len;
}
- $self->{write_set_watch} = 1 unless $self->{event_watch} & POLLOUT;
$self->watch_write(1);
return 0;
} elsif ($! == ECONNRESET) {
@@ -717,11 +715,7 @@ sub write {
DebugLevel >= 2 && $self->debugmsg("Wrote ALL %d bytes to %d (nq=%d)",
$written, $self->{fd}, $need_queue);
$self->{write_buf_offset} = 0;
-
- if ($self->{write_set_watch}) {
- $self->watch_write(0);
- $self->{write_set_watch} = 0;
- }
+ $self->watch_write(0);
# this was our only write, so we can return immediately
# since we avoided incrementing the buffer size or
@@ -739,7 +733,6 @@ sub write {
sub on_incomplete_write {
my PublicInbox::DS $self = shift;
- $self->{write_set_watch} = 1 unless $self->{event_watch} & POLLOUT;
$self->watch_write(1);
}
@@ -858,11 +851,6 @@ sub watch_write {
$event &= ~POLLOUT if ! $val;
$event |= POLLOUT if $val;
- if ($val && caller ne __PACKAGE__) {
- # A subclass registered interest, it's now responsible for this.
- $self->{write_set_watch} = 0;
- }
-
# If it changed, set it
if ($event != $self->{event_watch}) {
if ($HaveKQueue) {
--
EW
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 7/6] ds: remove PLCMap and per-socket PostLoopCallback
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
` (5 preceding siblings ...)
2019-06-03 1:52 ` [PATCH 6/6] ds: drop write_set_watch field Eric Wong
@ 2019-06-03 9:03 ` Eric Wong
6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2019-06-03 9:03 UTC (permalink / raw)
To: meta
We don't need and won't be needing per-socket PostLoopCallbacks.
---
lib/PublicInbox/DS.pm | 25 ++-----------------------
1 file changed, 2 insertions(+), 23 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 6b04e76..03612ce 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -58,7 +58,6 @@ our (
@ToClose, # sockets to close when event loop is done
$PostLoopCallback, # subref to call at the end of each loop, if defined (global)
- %PLCMap, # fd (num) -> PostLoopCallback (per-object)
$LoopTimeout, # timeout of event loop in milliseconds
$DoneInit, # if we've done the one-time module init yet
@@ -85,7 +84,6 @@ sub Reset {
@Timers = ();
$PostLoopCallback = undef;
- %PLCMap = ();
$DoneInit = 0;
# NOTE kqueue is close-on-fork, and we don't account for it, yet
@@ -389,18 +387,8 @@ The callback function will be passed two parameters: \%DescriptorMap
sub SetPostLoopCallback {
my ($class, $ref) = @_;
- if (ref $class) {
- # per-object callback
- my PublicInbox::DS $self = $class;
- if (defined $ref && ref $ref eq 'CODE') {
- $PLCMap{$self->{fd}} = $ref;
- } else {
- delete $PLCMap{$self->{fd}};
- }
- } else {
- # global callback
- $PostLoopCallback = (defined $ref && ref $ref eq 'CODE') ? $ref : undef;
- }
+ # global callback
+ $PostLoopCallback = (defined $ref && ref $ref eq 'CODE') ? $ref : undef;
}
# Internal function: run the post-event callback, send read events
@@ -426,11 +414,6 @@ sub PostEventLoop {
# or global) cancels it
my $keep_running = 1;
- # per-object post-loop-callbacks
- for my $plc (values %PLCMap) {
- $keep_running &&= $plc->(\%DescriptorMap);
- }
-
# now we're at the very end, call callback if defined
if (defined $PostLoopCallback) {
$keep_running &&= $PostLoopCallback->(\%DescriptorMap);
@@ -580,10 +563,6 @@ sub _cleanup {
}
}
- # now delete from mappings. this fd no longer belongs to us, so we don't want
- # to get alerts for it if it becomes writable/readable/etc.
- delete $PLCMap{$self->{fd}};
-
# we explicitly don't delete from DescriptorMap here until we
# actually close the socket, as we might be in the middle of
# processing an epoll_wait/etc that returned hundreds of fds, one
--
EW
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-06-03 9:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-03 1:52 [PATCH 0/6] ds: less is more Eric Wong
2019-06-03 1:52 ` [PATCH 1/6] ds: drop more unused subs Eric Wong
2019-06-03 1:52 ` [PATCH 2/6] ds: add a note about planned future changes Eric Wong
2019-06-03 1:52 ` [PATCH 3/6] ds: drop set_writer_func support Eric Wong
2019-06-03 1:52 ` [PATCH 4/6] ds: drop checks for invalid descriptors Eric Wong
2019-06-03 1:52 ` [PATCH 5/6] ds: drop unused EVENT: label in epoll code path Eric Wong
2019-06-03 1:52 ` [PATCH 6/6] ds: drop write_set_watch field Eric Wong
2019-06-03 9:03 ` [PATCH 7/6] ds: remove PLCMap and per-socket PostLoopCallback Eric Wong
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).