From owner-freebsd-net@freebsd.org Wed Jan 27 20:02:39 2016 Return-Path: Delivered-To: freebsd-net@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 2ED99A7055C for ; Wed, 27 Jan 2016 20:02:39 +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 13F661B27 for ; Wed, 27 Jan 2016 20:02:39 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: by mailman.ysv.freebsd.org (Postfix) id 107F8A7055A; Wed, 27 Jan 2016 20:02:39 +0000 (UTC) Delivered-To: net@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 EBD0AA70558; Wed, 27 Jan 2016 20:02:38 +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 95B9A1B24; Wed, 27 Jan 2016 20:02:38 +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 u0RK2VUL030962 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 27 Jan 2016 22:02:31 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u0RK2VUL030962 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u0RK2U3D030960; Wed, 27 Jan 2016 22:02:30 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 27 Jan 2016 22:02:30 +0200 From: Konstantin Belousov To: Boris Astardzhiev Cc: Kevin Oberman , Daniel Eischen , Gary Jennejohn , "freebsd-net@freebsd.org" , threads@freebsd.org, Luigi Rizzo Subject: Re: Does FreeBSD have sendmmsg or recvmmsg system calls? Message-ID: <20160127200230.GG74231@kib.kiev.ua> References: <20160124100747.551f8e3f@ernst.home> <20160126134005.GD3942@kib.kiev.ua> <20160126182543.64050678@ernst.home> <20160127013145.36f2aaef@ernst.home> <20160127132558.W985@besplex.bde.org> 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-net@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jan 2016 20:02:39 -0000 On Wed, Jan 27, 2016 at 12:14:02PM +0200, Boris Astardzhiev wrote: > Hello, > > I've made a few changes in the patch as recommended here starting with > the switch to ppoll(). I have a question since it's not quite clear to me > as written > in the manpage. Is it possible that ppoll() doesn't return an error and yet > revents > have set either POLLERR or POLLHUP or POLLNVAL? Ppoll() returned error means that the error is global for the syscall, i.e. the whole syscall execution was either impossible due to invalid parameters, or external event like signal delivery interrupted the execution. Individual file descriptors events like POLLHUP (EOF detected) or POLLNVAL (fd closed meantime) or POLLERR (whatever meaning the file type is provided for exceptional and not error situation) are not global errors. > +#include > +__FBSDID("$FreeBSD$"); > + > +#include > +#include > +#include > +#include Order sys/*.h alphabetically, except sys/types.h which comes first. Note that poll.h and stddef.h are not sys/, at least not for userspace consumers. > +#include "libc_private.h" > + > +#define POLLMASK (POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI) > +#define EPOLLMASK (POLLERR | POLLHUP | POLLNVAL) I do not like these definitions which are used once. They only make reading the code harder. I do not think that it is needed to check for EPOLLMASK. POLLHUP or POLLERR would result in the corresponding action on recvmsg(2), while you cannot realistically replicate the kernel logic to report the state, so it is better to delegate the handling to kernel. POLLNVAL means that the file descriptor was either invalid outright or closed during the call, i.e. a bug in the caller. > + > +ssize_t > +recvmmsg(int s, struct mmsghdr *__restrict msgvec, size_t vlen, int flags, > + const struct timespec *__restrict timeout) > +{ > + struct pollfd pfd[1]; > + size_t i, rcvd; > + ssize_t ret; > + int res; > + > + if (timeout != NULL) { > + pfd[0].fd = s; > + pfd[0].events = POLLMASK; > + pfd[0].revents = 0; > + res = ppoll(&pfd[0], 1, timeout, NULL); > + if (res == -1 || res == 0) > + return (res); > + if (pfd[0].revents & EPOLLMASK || > + (pfd[0].revents & POLLMASK) == 0) > + return (-1); > + } Fix the poll use and hopefully the patch is finished. Do you have any tests written ? Please provide me the tests.