Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jan 2016 09:31:55 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Boris Astardzhiev <boris.astardzhiev@gmail.com>
Cc:        Jilles Tjoelker <jilles@stack.nl>, net@freebsd.org, threads@freebsd.org
Subject:   Re: Does FreeBSD have sendmmsg or recvmmsg system calls?
Message-ID:  <20160120073154.GB3942@kib.kiev.ua>
In-Reply-To: <CAP=KkTzLCOnJVqt5F3ZuuZUiwkmWcne2Ynpi6-daE2jTzSBtfw@mail.gmail.com>
References:  <CAP=KkTwG0SVUmrBuWm33EC-tG4tMTdF5rLZQ_u6G1=-ujnfjkA@mail.gmail.com> <20160113080349.GC72455@kib.kiev.ua> <CAP=KkTxVaqZvigg78Dg%2Bv8kuTCaZyky8x15NHqD9uabuRKRkMw@mail.gmail.com> <20160116195657.GJ3942@kib.kiev.ua> <20160116202534.GK3942@kib.kiev.ua> <20160117211853.GA37847@stack.nl> <20160118044826.GS3942@kib.kiev.ua> <CAP=KkTy3J=k7hokGhohcGXv%2BWLnaxJmiAPxqmX9FHt7k0=Dp7Q@mail.gmail.com> <20160118140811.GW3942@kib.kiev.ua> <CAP=KkTzLCOnJVqt5F3ZuuZUiwkmWcne2Ynpi6-daE2jTzSBtfw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jan 19, 2016 at 01:58:27PM +0200, Boris Astardzhiev wrote:
> +int
> +recvmmsg(int s, struct mmsghdr *msgvec, unsigned int vlen, int flags)
> +{
> +	int i, ret, rcvd;
Shouldn't i and rcvd be unsigned as well ?  Shouldn't return value
also be unsigned ?
> +
> +	if (vlen > VLEN_MAX)
> +		vlen = VLEN_MAX;
Why is this restriction needed ?

> +
> +	rcvd = 0;
> +	for (i = 0; i < vlen; i++) {
> +		errno = 0;
> +		ret = __sys_recvmsg(s, &msgvec[i].msg_hdr, flags);
> +		if (ret < 0 || errno != 0) {
I do not see why do you need to clear errno before, and then do this test.
Just check ret == -1, in which case errno was set from the immediate syscall.

> +			if (rcvd != 0) {
> +				/* We've received messages. Let caller know. */
> +				errno = 0;
This cleaning is not needed as well.  For successfull functions returns,
errno value is undefined.

> +				return (rcvd);
> +			}
> +			return (-1);
> +		}
> +
> +		/* Save received bytes */
> +		msgvec[i].msg_len = ret;
> +
Extra empty line.
> +		rcvd++;
> +	}
> +
> +	return (rcvd);
> +}



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