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 2/4] syscall: more idiomatic cmsghdr space allocation
  2022-04-18  9:50  6% [PATCH 0/4] lei: finish wiring up pure-Perl stuff for Linux Eric Wong
@ 2022-04-18  9:50  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2022-04-18  9:50 UTC (permalink / raw)
  To: meta

Since we know the space required under Linux, we can use the
same initialization as the Inline::C version instead of
hard-coding 256 as we do for Socket::MsgHdr.
---
 lib/PublicInbox/Syscall.pm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index e972aa41..cc282f9f 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -418,6 +418,7 @@ sub CMSG_ALIGN ($) { ($_[0] + SIZEOF_size_t - 1) & ~(SIZEOF_size_t - 1) }
 use constant CMSG_ALIGN_SIZEOF_cmsghdr => CMSG_ALIGN(SIZEOF_cmsghdr);
 sub CMSG_SPACE ($) { CMSG_ALIGN($_[0]) + CMSG_ALIGN_SIZEOF_cmsghdr }
 sub CMSG_LEN ($) { CMSG_ALIGN_SIZEOF_cmsghdr + $_[0] }
+use constant msg_controllen => CMSG_SPACE(10 * SIZEOF_int) + 16; # 10 FDs
 
 if (defined($SYS_sendmsg) && defined($SYS_recvmsg)) {
 no warnings 'once';
@@ -457,7 +458,7 @@ no warnings 'once';
 *recv_cmd4 = sub ($$$) {
 	my ($sock, undef, $len) = @_;
 	vec($_[1], ($len + 1) * 8, 1) = 0;
-	vec(my $cmsghdr = '', 256 * 8 - 1, 1) = 1;
+	my $cmsghdr = "\0" x msg_controllen; # 10 * sizeof(int)
 	my $iov = pack('P'.TMPL_size_t, $_[1], $len);
 	my $mh = pack('PL' . # msg_name, msg_namelen (socklen_t (U32))
 			BYTES_4_hole . # 4-byte padding on 64-bit
@@ -468,7 +469,7 @@ no warnings 'once';
 			@BYTES_4_hole,
 			$iov, 1, # msg_iov, msg_iovlen
 			$cmsghdr, # msg_control
-			256, # msg_controllen
+			msg_controllen,
 			0); # msg_flags
 	my $r = syscall($SYS_recvmsg, fileno($sock), $mh, 0);
 	return (undef) if $r < 0; # $! set

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/4] lei: finish wiring up pure-Perl stuff for Linux
@ 2022-04-18  9:50  6% Eric Wong
  2022-04-18  9:50  7% ` [PATCH 2/4] syscall: more idiomatic cmsghdr space allocation Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2022-04-18  9:50 UTC (permalink / raw)
  To: meta

Some cleanups here, too; but this hopefully makes lei more
accessible to users who don't have space/bandwidth to use
Inline::C.

I thought I sent these out weeks ago, but Real-Life, power outages
and other lei problems got in the way, I guess :x

Eric Wong (4):
  lei: clobber recvmsg buffer on errors
  syscall: more idiomatic cmsghdr space allocation
  lei: wire up pure Perl sendmsg/recvmsg for Linux users
  syscall: golf + more idiomatic buffer initialization

 lib/PublicInbox/IPC.pm           |  4 ++++
 lib/PublicInbox/LEI.pm           |  4 ++++
 lib/PublicInbox/LeiSelfSocket.pm |  1 +
 lib/PublicInbox/Syscall.pm       | 13 ++++++-------
 lib/PublicInbox/TestCommon.pm    | 16 ++++++++++++----
 t/lei-daemon.t                   |  6 +++++-
 t/lei-externals.t                |  1 +
 7 files changed, 33 insertions(+), 12 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2022-04-18  9:50  6% [PATCH 0/4] lei: finish wiring up pure-Perl stuff for Linux Eric Wong
2022-04-18  9:50  7% ` [PATCH 2/4] syscall: more idiomatic cmsghdr space allocation Eric Wong

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).