From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6906F1F4DA for ; Mon, 18 Apr 2022 09:50:05 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/4] syscall: more idiomatic cmsghdr space allocation Date: Mon, 18 Apr 2022 09:50:02 +0000 Message-Id: <20220418095004.466-3-e@80x24.org> In-Reply-To: <20220418095004.466-1-e@80x24.org> References: <20220418095004.466-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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