From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753735AbdEEKeJ (ORCPT ); Fri, 5 May 2017 06:34:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46376 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751752AbdEEKeI (ORCPT ); Fri, 5 May 2017 06:34:08 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 77A6880C04 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=swhiteho@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 77A6880C04 Subject: Re: Question about SOCK_SEQPACKET To: Sowmini Varadhan References: <20170505100926.GD1547@oracle.com> Cc: Sam Kumar , linux-kernel@vger.kernel.org, "netdev@vger.kernel.org" From: Steven Whitehouse Message-ID: Date: Fri, 5 May 2017 11:34:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20170505100926.GD1547@oracle.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 May 2017 10:34:07 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 05/05/17 11:09, Sowmini Varadhan wrote: > On (05/05/17 10:45), Steven Whitehouse wrote: >> I do wonder if the man page for recvmsg is wrong, or at least a bit >> confusing. SOCK_SEQPACKET is stream based not message based - it just >> happens to have EOR markers in the stream. There is no reason that the whole >> message needs to be returned in a single read, and in fact that would be >> impossible if the sender didn't insert any EOR markers but kept sending data >> beyond the size that the socket could buffer. >> >> I notice that man 7 socket says SOCK_SEQPACKET is for datagrams of fixed >> maximum length which is definitely wrong, as is the statement that a >> consumer has to read an entire packet with each system call. > Which man page do you think is wrong here? The POSIX definition is here > > http://pubs.opengroup.org/onlinepubs/009695399/functions/recvmsg.html > > The description in > > http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_10.html > > says, "It is protocol-specific whether a maximum record size is imposed." > In my machine (Ubuntu 4.4.0-72, and it is in socket(2), not socket(7), btw) > doesnt have any references to max length, but I'm not sure I'd boldly assert > "definitely wrong" about the requirement of having to read entire > packet in a system call (see POSIX man page) > > --Sowmini > Just before the part that you've quoted, the description for SOCK_SEQPACKET says: "The SOCK_SEQPACKET socket type is similar to the SOCK_STREAM type, and is also connection-oriented. The only difference between these types is that record boundaries are maintained using the SOCK_SEQPACKET type. A record can be sent using one or more output operations and received using one or more input operations, but a single operation never transfers parts of more than one record." The man page for socket says SOCK_SEQPACKET "Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length" which is not true, because while there may be a length restriction, it is quite possible that there is not a length restriction (as per DECnet). It also says "a consumer is required to read an entire packet with each input system call" which is also contradicted by POSIX which says that a record can be "received using one or more input operations". So both statements in the man page are wrong, I think. I have to say that I'd not spotted the POSIX recvmsg wording before, which says "For message-based sockets, such as SOCK_DGRAM and SOCK_SEQPACKET, the entire message shall be read in a single operation" however that does contradict the earlier wording, where it explicitly says that multiple receive operations per record are ok for SOCK_SEQPACKET - at least if we assume that record == message in this case. Also, if this restriction was true (one message per recvmsg call) then MSG_EOR would never be needed on receive, since every recvmsg would be a single message/record only, and that same document does say that MSG_EOR can be set on receive for protocols which support it, Steve.