unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/9] daemon: make SO_ACCEPTFILTER a shared variable
Date: Fri,  1 Oct 2021 09:54:39 +0000	[thread overview]
Message-ID: <20211001095445.9326-4-e@80x24.org> (raw)
In-Reply-To: <20211001095445.9326-1-e@80x24.org>

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');
 	};
 

  parent reply	other threads:[~2021-10-01  9:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01  9:54 [PATCH 0/9] daemon-related things Eric Wong
2021-10-01  9:54 ` [PATCH 1/9] doc: lei-security: some more updates Eric Wong
2021-10-01  9:54 ` [PATCH 2/9] listener: switch to level-triggered epoll Eric Wong
2021-10-01  9:54 ` Eric Wong [this message]
2021-10-01  9:54 ` [PATCH 4/9] ipc: run Net::SSLeay::randomize Eric Wong
2021-10-01  9:54 ` [PATCH 5/9] ds: simplify signalfd use Eric Wong
2021-10-01  9:54 ` [PATCH 6/9] inbox: inline and eliminate git_cleanup Eric Wong
2021-10-01  9:54 ` [PATCH 7/9] inbox: keep DB handles if git processes are live Eric Wong
2021-10-01  9:54 ` [PATCH 8/9] ds: inline set_cloexec Eric Wong
2021-10-01  9:54 ` [PATCH 9/9] doc: lei-daemon: new manpage Eric Wong
2021-10-02  0:19   ` Kyle Meyer
2021-10-02  8:08     ` Eric Wong
2021-10-04  3:16       ` Kyle Meyer

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: https://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=20211001095445.9326-4-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.
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).