Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Jan 2016 11:35:09 +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:  <20160121093509.GK3942@kib.kiev.ua>
In-Reply-To: <CAP=KkTx3dAUuSBrJiwNAAe%2BhHSG4j5Qp7sAcgtOgmVi8a12k1A@mail.gmail.com>
References:  <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> <20160120073154.GB3942@kib.kiev.ua> <CAP=KkTx3dAUuSBrJiwNAAe%2BhHSG4j5Qp7sAcgtOgmVi8a12k1A@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

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.


home | help

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