From owner-freebsd-hackers@freebsd.org Mon Sep 10 08:58:37 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 0392E1083BD9 for ; Mon, 10 Sep 2018 08:58:37 +0000 (UTC) (envelope-from sghctoma@gmail.com) Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 6AB9F76C9B for ; Mon, 10 Sep 2018 08:58:36 +0000 (UTC) (envelope-from sghctoma@gmail.com) Received: by mail-wr1-x431.google.com with SMTP id 20-v6so20987574wrb.12 for ; Mon, 10 Sep 2018 01:58:36 -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:mime-version :content-disposition:user-agent; bh=fbK8KO/TC71yUENviQCMDr9zd8Aw//3DeVbAwaojFug=; b=B6o5Dkq4sQjW5DSXsN+VeGdAMEdno2mwCLsUaxr/HpQzuLo5wBYgbCl/4iegRdzru+ 0GVnBRWXkrJD4/Z94nBqJ4Ab8amm7itbmZhoee8MLMP7r7tdQTIVXzPA1dbPEGE9oppx 9qaECgDuqZaviVvsmRaEc/4RHhlqsj0dRCfLV0RZE5f7r8Ej6YY52jOUZsw2KfqYPMGR Z7zZO7B3tj151eeZwPbx5aDYkKdnIMJF+vSAS+I7cDbnFGMlMJ/uOgLuWTmfzpVeJehU PPMhgE5dX9tpdCr/N9DhbS1eXOwh2vlNhwBbiPBiIqI5yCT0bo1QFJbWaOEsrXazK5Hg BtqA== 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 :mime-version:content-disposition:user-agent; bh=fbK8KO/TC71yUENviQCMDr9zd8Aw//3DeVbAwaojFug=; b=HkCepBalxS2fQMSeDCZweqbSkxXDjDv1tIDcN0U/+sL9V03Gqvxm53d4lOZeWWrw+9 gGze9qS5C8cFZHGEwQxeVHbjPVJbQ3+xuy9hqvoAt9ioR5BveHRWXqRVsL/krBZlbXrW G0oKkK2Yez6bjJHhTrZ7PRyBBhwBvy93HfmT+lJr3mfnodwbxM0UsKDFrblllK7K52WG pJYTlCt+RSPCXiVvCoO3VWsOmSmIdg70Y2DAMUrMgYayLewSy9Hl1QTKCN/cu878oEr8 uiZY+gMW2okBtPUl6Evcz4I61VC5Um5eP4f1yJiEnR9+kwQzDkcBuElKRA4eeRZblTRA hkEg== X-Gm-Message-State: APzg51BKiNAGpfnBz1z99fkx0KTHBY66rGafhkQxudXEAzXq9+T9W//2 ZT/WIN5WokZMPsiLg8/pvzPvTbDW X-Google-Smtp-Source: ANB0VdZpAm9LMAkWOf11pYPNc7R2nq9cMVvuLTrDwf7y6oFvhXZoB5XC5NtLq7L4TQuiZ/76+4InNA== X-Received: by 2002:adf:ad34:: with SMTP id p49-v6mr14764628wrc.10.1536569914964; Mon, 10 Sep 2018 01:58:34 -0700 (PDT) Received: from localhost (pr-audit.hu. [86.101.233.9]) by smtp.gmail.com with ESMTPSA id s131-v6sm17523332wmf.2.2018.09.10.01.58.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Sep 2018 01:58:34 -0700 (PDT) Date: Mon, 10 Sep 2018 10:58:33 +0200 From: Tamas Szakaly To: freebsd-hackers@freebsd.org Subject: Attempting to receivce zero-length message with recvmsg Message-ID: <20180910085833.d4py4ladlyqchjvo@pamparam> Mail-Followup-To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 08:58:37 -0000 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 -- Tamas Szakaly @sghctoma