From owner-freebsd-threads@freebsd.org Thu Jan 21 09:35:17 2016 Return-Path: Delivered-To: freebsd-threads@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3E569A8920E for ; Thu, 21 Jan 2016 09:35:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 236001D42 for ; Thu, 21 Jan 2016 09:35:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: by mailman.ysv.freebsd.org (Postfix) id 1E9A9A89208; Thu, 21 Jan 2016 09:35:17 +0000 (UTC) Delivered-To: threads@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 04132A89202; Thu, 21 Jan 2016 09:35:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A2AB21D40; Thu, 21 Jan 2016 09:35:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u0L9Z99s097441 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 21 Jan 2016 11:35:09 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u0L9Z99s097441 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u0L9Z9Kr097440; Thu, 21 Jan 2016 11:35:09 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 21 Jan 2016 11:35:09 +0200 From: Konstantin Belousov To: Boris Astardzhiev Cc: Jilles Tjoelker , net@freebsd.org, threads@freebsd.org Subject: Re: Does FreeBSD have sendmmsg or recvmmsg system calls? Message-ID: <20160121093509.GK3942@kib.kiev.ua> References: <20160116195657.GJ3942@kib.kiev.ua> <20160116202534.GK3942@kib.kiev.ua> <20160117211853.GA37847@stack.nl> <20160118044826.GS3942@kib.kiev.ua> <20160118140811.GW3942@kib.kiev.ua> <20160120073154.GB3942@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2016 09:35:17 -0000 On Wed, Jan 20, 2016 at 10:29:47AM +0200, Boris Astardzhiev wrote: > Let me know the final decision then - whether in the existing manpages or > in new files. Decide it yourself, it is your patch. If you are fine with writing new man page, I do not object. > > jt>The Linux version has an additional parameter struct timespec *timeout > jt>(but only for recvmmsg, not for sendmmsg). Note that implementing this > jt>in a Linux-compatible manner has low overhead, since Linux only checks > jt>it between packets and never interrupts a wait because of this timeout > jt>(source: http://man7.org/linux/man-pages/man2/recvmmsg.2.html ). > > That's right. Shall I try to implement the timeout part or leave > it the way it is now? I do not see any sense in making the functions with signature or semantic different from Linux version. Right now, the goal of including the patch is compatibility. > > kb>Shouldn't i and rcvd be unsigned as well ? Shouldn't return value > kb>also be unsigned ? > I think i and rcvd should be unsigned whereas ret should not - after all > if an error occurred we get -1. I looked at the real signatures and man pages for the Linux functions, finally. There is indeed the timeout arg, the MSG_WAITFORONE flag for recvmmsg(3), and Linux uses ints for what would be naturally size_t. > kb>> + > kb>> + rcvd = 0; > kb>> + for (i = 0; i < vlen; i++) { > kb>> + errno = 0; > kb>> + ret = __sys_recvmsg(s, &msgvec[i].msg_hdr, flags); > kb>> + if (ret < 0 || errno != 0) { > kb>I do not see why do you need to clear errno before, and then do this > test. > kb>Just check ret == -1, in which case errno was set from the immediate > syscall. > kb> > kb>> + if (rcvd != 0) { > kb>> + /* We've received messages. Let caller > know. */ > kb>> + errno = 0; > kb>This cleaning is not needed as well. For successfull functions returns, > kb>errno value is undefined. > > Wouldn't I confuse apps if they check errno in the follow case - I want to > receive two messages. The first __sys_recvmsg succeeds and then for the > second __sys_recvmsg fails. Thus errno will be != 0 and I'm telling the app > that I have received one message by returning 1 but errno will be != 0. > Is this correct? errno value is only defined after the function explicitely returned error. Apps which test for errno without testing for error are wrong.