From owner-freebsd-hackers@freebsd.org Mon Sep 10 17:10:57 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 128511096438 for ; Mon, 10 Sep 2018 17:10:57 +0000 (UTC) (envelope-from sghctoma@gmail.com) Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 808AC8BF85 for ; Mon, 10 Sep 2018 17:10:56 +0000 (UTC) (envelope-from sghctoma@gmail.com) Received: by mail-wr1-x441.google.com with SMTP id w11-v6so22769267wrc.5 for ; Mon, 10 Sep 2018 10:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=BpXwXNWA6BqvkS8/2H8OIPrQ1JpXw2Sy0C2reey5QAw=; b=fdkZ81FTgeDiesDQnEH7nh0MVavNyyCH/NV5ZfH7/2KItdSczQQCAkNiTdMTF+tFy/ d4cJMrYiZ7odwRW+z5Gb5aSBd4X4ypKKNZDujhe6H1h+3We2iTF/f8UwuDhEjIgyPmHR iSe6FcogagKCi82a/KlY6vfi4Yd23RjWW6mV5LtsBQM4ctpwqm4U5VsbcvDTgI9PVyMB mnIGWrpKDsrOwzrE/6riqgKDHcgfOPUjZHg8WK+TYM++9zWhXOPSg0uDEA0LtISivpN+ AJXz5DOPEs0W1fW5No1rX26ztR8Pf2vg+Ob+Mo+8g2IHJdBMZHT62OfREB9zGlUvPHEL k5eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=BpXwXNWA6BqvkS8/2H8OIPrQ1JpXw2Sy0C2reey5QAw=; b=d5vYJkm21HltdL9jVXJ093WzrWqbcXpCq/fO8YP6N3gfrdQWfxpET0I/Kal/hmkUYv HvCGUf/vjmii2eMDw45WB1rf5Nzsf11BBDyPWOtpZcFBHrAR+gjw1YzZpVEKje9OLyEI oX/EDZm7+SwnZnrGUHVIJNWZBlYeTEPoAcVnXhnSIwlmdOpNOOQmPra53BmnwffaSC+V 9p8Hu5ZbeZeg6bQ+fsRnfp7P86i6Z4UfOhb/qAG1fTWKnvFQ13gEE41X1yPFnrry3BlB fuCrcuVGlW3JIpH1xAJYyHfc6Aud0FJ/99xpaiOakNs4Un8HqfMT8Lh07/ph51MAYmKU FIag== X-Gm-Message-State: APzg51BxcHBzwsYwvVR5Mqq/AKtNLShL1K8/xGN4XEzhv9bk+ev+vNss R0whMTMKfteK7MeuxQ/3whiKqhg8 X-Google-Smtp-Source: ANB0VdbqP/dYDbLIq640lK7CBNRZHSbE2I+/t+PjF+QkIOdwuW6ph9TripRmbGNzUqMaTXiAUK1/4A== X-Received: by 2002:adf:94c5:: with SMTP id 63-v6mr16665344wrr.247.1536599455112; Mon, 10 Sep 2018 10:10:55 -0700 (PDT) Received: from localhost (catv-176-63-26-157.catv.broadband.hu. [176.63.26.157]) by smtp.gmail.com with ESMTPSA id q200-v6sm15191770wmd.2.2018.09.10.10.10.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Sep 2018 10:10:54 -0700 (PDT) Date: Mon, 10 Sep 2018 19:10:53 +0200 From: Tamas Szakaly To: freebsd-hackers@freebsd.org Subject: Re: Attempting to receivce zero-length message with recvmsg Message-ID: <20180910171053.3jvgw3i7fp6hetxe@pamparam> Mail-Followup-To: freebsd-hackers@freebsd.org References: <20180910085833.d4py4ladlyqchjvo@pamparam> <20180910172832.2c0a1357@ernst.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180910172832.2c0a1357@ernst.home> User-Agent: NeoMutt/20180716 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Sep 2018 17:10:57 -0000 On Mon, Sep 10, 2018 at 05:28:32PM +0200, Gary Jennejohn wrote: > On Mon, 10 Sep 2018 10:58:33 +0200 > Tamas Szakaly wrote: > > > Hi, > > > > I have a question about the recvmsg syscall. According to POSIX, unless > > O_NONBLOCK is set on the socket fd, recvmsg [1] should block until a message > > arrives. However, recvmsg returns immediately with 0, if we are trying to > > receive a 0-byte message from a SOCK_SEQPACKET AF_UNIX socket. Consider the > > following code: > > > > #include > > #include > > > > int main(int argc, char** argv) { > > int sock[2]; > > socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sock); > > > > struct msghdr msghdr = {0}; > > int ret = recvmsg(sock[1], &msghdr, 0); > > > > printf("ret=%d, msghdr.msg_flags=0x%08x\n\n", ret, msghdr.msg_flags); > > } > > > > Running this yields this output: > > > > [0x00 socketstuff]$ cc socketpair.c -o socketpair && ./socketpair > > ret=0, msghdr.msg_flags=0x00000000 > > > > You can see that recvmsg returns with 0, even though there were no messages > > sent, and neither of the sockets are closed, so it should block indefinitely. > > > > Is this behavior intentional to match the semantics of read [2] (i.e. > > attempting to read zero bytes should be a no-op)? > > > > > > [1] recvmsg: http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html > > [2] read: http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html > > > > You have to initalize msghdr.msg_iov and msghde.iov_len, otherwise > the kernel notices there is no place to put a received message and > simply returns 0. > > I did that and recvmsg() did not return. > > -- > Gary Jennejohn > That's okay, but I want to receive exactly zero bytes. I can send such messages with sendmsg, and I would like to receive them. Of course I can introduce some dummy variable to initialize msg_iov and iov_len with, but it will never be used, and it just feels ugly. -- Tamas Szakaly @sghctoma