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 3/9] daemon: make SO_ACCEPTFILTER a shared variable
  2021-10-01  9:54  6% [PATCH 0/9] daemon-related things Eric Wong
@ 2021-10-01  9:54  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-10-01  9:54 UTC (permalink / raw)
  To: meta

Constant subroutines use more memory and there's no need to
optimize it for inlining since it's only used at startup.
---
 lib/PublicInbox/Daemon.pm | 6 +++---
 t/httpd-corner.t          | 4 ++--
 t/httpd-https.t           | 6 ++++--
 t/httpd.t                 | 6 ++++--
 t/imapd-tls.t             | 7 ++++---
 t/nntpd-tls.t             | 7 ++++---
 6 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 727311a4aa10..24dc7791b43d 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -12,7 +12,6 @@ use IO::Handle; # ->autoflush
 use IO::Socket;
 use POSIX qw(WNOHANG :signal_h);
 use Socket qw(IPPROTO_TCP SOL_SOCKET);
-sub SO_ACCEPTFILTER () { 0x1000 }
 STDOUT->autoflush(1);
 STDERR->autoflush(1);
 use PublicInbox::DS qw(now);
@@ -21,6 +20,7 @@ require PublicInbox::Listener;
 use PublicInbox::EOFpipe;
 use PublicInbox::Sigfd;
 use PublicInbox::GitAsyncCat;
+our $SO_ACCEPTFILTER = 0x1000;
 my @CMD;
 my ($set_user, $oldset);
 my (@cfg_listen, $stdout, $stderr, $group, $user, $pid_file, $daemonize);
@@ -579,10 +579,10 @@ sub defer_accept ($$) {
 		return if $sec > 0; # systemd users may set a higher value
 		setsockopt($s, IPPROTO_TCP, $TCP_DEFER_ACCEPT, 1);
 	} elsif ($^O eq 'freebsd') {
-		my $x = getsockopt($s, SOL_SOCKET, SO_ACCEPTFILTER);
+		my $x = getsockopt($s, SOL_SOCKET, $SO_ACCEPTFILTER);
 		return if defined $x; # don't change if set
 		my $accf_arg = pack('a16a240', $af_name, '');
-		setsockopt($s, SOL_SOCKET, SO_ACCEPTFILTER, $accf_arg);
+		setsockopt($s, SOL_SOCKET, $SO_ACCEPTFILTER, $accf_arg);
 	}
 }
 
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index 5dc5734e96d1..cec754c9c13a 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -36,7 +36,7 @@ if ($^O eq 'linux') {
 	}
 } elsif ($^O eq 'freebsd' && system('kldstat -m accf_data >/dev/null') == 0) {
 	require PublicInbox::Daemon;
-	my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
+	my $var = $PublicInbox::Daemon::SO_ACCEPTFILTER;
 	$accf_arg = pack('a16a240', 'dataready', '');
 	setsockopt($sock, SOL_SOCKET, $var, $accf_arg) or die "setsockopt: $!";
 }
@@ -596,7 +596,7 @@ SKIP: {
 SKIP: {
 	skip 'SO_ACCEPTFILTER is FreeBSD-only', 1 if $^O ne 'freebsd';
 	skip 'accf_data not loaded: kldload accf_data' if !defined $accf_arg;
-	my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
+	my $var = $PublicInbox::Daemon::SO_ACCEPTFILTER;
 	defined(my $x = getsockopt($sock, SOL_SOCKET, $var)) or die;
 	is($x, $accf_arg, 'SO_ACCEPTFILTER unchanged if previously set');
 };
diff --git a/t/httpd-https.t b/t/httpd-https.t
index bf7d3f94de6c..d42d7c509949 100644
--- a/t/httpd-https.t
+++ b/t/httpd-https.t
@@ -98,8 +98,10 @@ for my $args (
 			skip 'accf_data not loaded? kldload accf_data', 2;
 		}
 		require PublicInbox::Daemon;
-		my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
-		my $x = getsockopt($https, SOL_SOCKET, $var);
+		ok(defined($PublicInbox::Daemon::SO_ACCEPTFILTER),
+			'SO_ACCEPTFILTER defined');
+		my $x = getsockopt($https, SOL_SOCKET,
+				$PublicInbox::Daemon::SO_ACCEPTFILTER);
 		like($x, qr/\Adataready\0+\z/, 'got dataready accf for https');
 	};
 
diff --git a/t/httpd.t b/t/httpd.t
index 849f61bb82ce..aa6012103141 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -109,8 +109,10 @@ SKIP: {
 		skip 'accf_http not loaded: kldload accf_http', 1;
 	}
 	require PublicInbox::Daemon;
-	my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
-	my $x = getsockopt($sock, SOL_SOCKET, $var);
+	ok(defined($PublicInbox::Daemon::SO_ACCEPTFILTER),
+		'SO_ACCEPTFILTER defined');
+	my $x = getsockopt($sock, SOL_SOCKET,
+			$PublicInbox::Daemon::SO_ACCEPTFILTER);
 	like($x, qr/\Ahttpready\0+\z/, 'got httpready accf for HTTP');
 };
 
diff --git a/t/imapd-tls.t b/t/imapd-tls.t
index 73f5112fcb72..44ab350c95b3 100644
--- a/t/imapd-tls.t
+++ b/t/imapd-tls.t
@@ -176,10 +176,11 @@ for my $args (
 			skip 'accf_data not loaded? kldload accf_data', 2;
 		}
 		require PublicInbox::Daemon;
-		my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
-		my $x = getsockopt($imaps, SOL_SOCKET, $var);
+		my $x = getsockopt($imaps, SOL_SOCKET,
+				$PublicInbox::Daemon::SO_ACCEPTFILTER);
 		like($x, qr/\Adataready\0+\z/, 'got dataready accf for IMAPS');
-		$x = getsockopt($starttls, IPPROTO_TCP, $var);
+		$x = getsockopt($starttls, IPPROTO_TCP,
+				$PublicInbox::Daemon::SO_ACCEPTFILTER);
 		is($x, undef, 'no BSD accept filter for plain IMAP');
 	};
 
diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t
index 9af6c25443a0..d81d1e1303fc 100644
--- a/t/nntpd-tls.t
+++ b/t/nntpd-tls.t
@@ -168,10 +168,11 @@ for my $args (
 			skip 'accf_data not loaded? kldload accf_data', 2;
 		}
 		require PublicInbox::Daemon;
-		my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
-		my $x = getsockopt($nntps, SOL_SOCKET, $var);
+		my $x = getsockopt($nntps, SOL_SOCKET,
+				$PublicInbox::Daemon::SO_ACCEPTFILTER);
 		like($x, qr/\Adataready\0+\z/, 'got dataready accf for NNTPS');
-		$x = getsockopt($starttls, IPPROTO_TCP, $var);
+		$x = getsockopt($starttls, IPPROTO_TCP,
+				$PublicInbox::Daemon::SO_ACCEPTFILTER);
 		is($x, undef, 'no BSD accept filter for plain NNTP');
 	};
 

^ permalink raw reply	[relevance 7%]

* [PATCH 0/9] daemon-related things
@ 2021-10-01  9:54  6% Eric Wong
  2021-10-01  9:54  7% ` [PATCH 3/9] daemon: make SO_ACCEPTFILTER a shared variable Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-10-01  9:54 UTC (permalink / raw)
  To: meta

5/9 has been a long-time coming, a few other small things, too.
The diff stat for lib/ alone shows a nice reduction

Eric Wong (9):
  doc: lei-security: some more updates
  listener: switch to level-triggered epoll
  daemon: make SO_ACCEPTFILTER a shared variable
  ipc: run Net::SSLeay::randomize
  ds: simplify signalfd use
  inbox: inline and eliminate git_cleanup
  inbox: keep DB handles if git processes are live
  ds: inline set_cloexec
  doc: lei-daemon: new manpage

 Documentation/lei-daemon.pod       |  61 ++++++++++++++++
 Documentation/lei-security.pod     |   5 +-
 Documentation/lei.pod              |   9 ++-
 Documentation/lei_design_notes.txt |   2 +-
 MANIFEST                           |   1 +
 Makefile.PL                        |   2 +-
 lib/PublicInbox/ConfigIter.pm      |   2 +-
 lib/PublicInbox/DS.pm              | 110 ++++++++++++++---------------
 lib/PublicInbox/DSKQXS.pm          |  10 +--
 lib/PublicInbox/Daemon.pm          |  20 ++----
 lib/PublicInbox/ExtMsg.pm          |   2 +-
 lib/PublicInbox/ExtSearchIdx.pm    |  12 +---
 lib/PublicInbox/Gcf2Client.pm      |   4 +-
 lib/PublicInbox/Git.pm             |   4 +-
 lib/PublicInbox/IPC.pm             |   5 +-
 lib/PublicInbox/Inbox.pm           |  41 +++++------
 lib/PublicInbox/LEI.pm             |  17 +----
 lib/PublicInbox/Listener.pm        |   5 +-
 lib/PublicInbox/Qspawn.pm          |   2 +-
 lib/PublicInbox/Sigfd.pm           |  10 +--
 lib/PublicInbox/Syscall.pm         |  12 ++--
 lib/PublicInbox/Watch.pm           |   3 +-
 script/public-inbox-watch          |   9 ---
 t/dir_idle.t                       |   6 +-
 t/ds-leak.t                        |   4 +-
 t/httpd-corner.t                   |   4 +-
 t/httpd-https.t                    |   6 +-
 t/httpd.t                          |   6 +-
 t/imapd-tls.t                      |   7 +-
 t/imapd.t                          |   6 +-
 t/nntpd-tls.t                      |   7 +-
 t/nntpd.t                          |   2 +-
 t/sigfd.t                          |   7 +-
 t/watch_maildir.t                  |   2 +-
 xt/mem-imapd-tls.t                 |   6 +-
 xt/net_writer-imap.t               |   2 +-
 36 files changed, 221 insertions(+), 192 deletions(-)
 create mode 100644 Documentation/lei-daemon.pod

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | sort options + mbox downloads above
-- links below jump to the message on this page --
2021-10-01  9:54  6% [PATCH 0/9] daemon-related things Eric Wong
2021-10-01  9:54  7% ` [PATCH 3/9] daemon: make SO_ACCEPTFILTER a shared variable Eric Wong

Code repositories for project(s) associated with this 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).