Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jan 2016 22:02:30 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Boris Astardzhiev <boris.astardzhiev@gmail.com>
Cc:        Kevin Oberman <rkoberman@gmail.com>, Daniel Eischen <deischen@freebsd.org>, Gary Jennejohn <gljennjohn@gmail.com>, "freebsd-net@freebsd.org" <net@freebsd.org>, threads@freebsd.org, Luigi Rizzo <rizzo@iet.unipi.it>
Subject:   Re: Does FreeBSD have sendmmsg or recvmmsg system calls?
Message-ID:  <20160127200230.GG74231@kib.kiev.ua>
In-Reply-To: <CAP=KkTwEGVhKxSmZUDsq4hJ9K_nHrO9di1maS7zVn2CNX8TqAg@mail.gmail.com>
References:  <20160124100747.551f8e3f@ernst.home> <CAP=KkTyHG9Rb%2BnrDC1TDxzjUQFca9NkVp8Suo1c_-C00RUtkuQ@mail.gmail.com> <20160126134005.GD3942@kib.kiev.ua> <CA%2BhQ2%2BivWYJMDUwzdZGW88-mWzSVfPzX212sOFVmxxN0hpZ%2BQQ@mail.gmail.com> <20160126182543.64050678@ernst.home> <Pine.GSO.4.64.1601261743450.12995@sea.ntplx.net> <20160127013145.36f2aaef@ernst.home> <20160127132558.W985@besplex.bde.org> <CAN6yY1snu5YkXbTTHku4OAE6UyoQ5ibyM79KgHUN2dzRgvXSuA@mail.gmail.com> <CAP=KkTwEGVhKxSmZUDsq4hJ9K_nHrO9di1maS7zVn2CNX8TqAg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/cdefs.h>
> +__FBSDID("$FreeBSD$");
> +
> +#include <sys/types.h>
> +#include <sys/socket.h>
> +#include <sys/poll.h>
> +#include <sys/stddef.h>
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160127200230.GG74231>