From owner-freebsd-net@freebsd.org Tue Jan 26 18:14:26 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 9805AA4608A for ; Tue, 26 Jan 2016 18:14:26 +0000 (UTC) (envelope-from rizzo.unipi@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 75DA215F5 for ; Tue, 26 Jan 2016 18:14:26 +0000 (UTC) (envelope-from rizzo.unipi@gmail.com) Received: by mailman.ysv.freebsd.org (Postfix) id 70F4BA46087; Tue, 26 Jan 2016 18:14:26 +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 70606A46083; Tue, 26 Jan 2016 18:14:26 +0000 (UTC) (envelope-from rizzo.unipi@gmail.com) Received: from mail-lf0-x231.google.com (mail-lf0-x231.google.com [IPv6:2a00:1450:4010:c07::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E9D2E15F3; Tue, 26 Jan 2016 18:14:25 +0000 (UTC) (envelope-from rizzo.unipi@gmail.com) Received: by mail-lf0-x231.google.com with SMTP id h129so111622398lfh.3; Tue, 26 Jan 2016 10:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=hTvcC4x4nkGZQkTbFcNmtsBXR1OfB93MFgFMljHxXKU=; b=t3iYSgh47O+EvP8w7zQrJFwm9b1vHBgUA4BEBjezASflmuVSJI6gBd275zmwVThcoj KhZN7Z2xnnTtdTMG79cH4A6IDGfdpfCm9FxZpr3ZdYUIX0HTlSrEXp8+zFwugK32p545 hOylvtpuHa5aXw50JzGiDoDjATmbjWD/OVUjW0XukSAO+4kAuotFlvSOxEAhHD8eda2d JigciaZfEWTt+bAMB6oAGINUF7rUsfBlNT7/o/5QQ6fulH3YnOUd64SP2+q62SQVL/SJ 36Y3y8l1A8kCbOTQOwGXA1p0dfqnZs7Gkdt+zviQiD6ACrbihcWMy8AMc7JIsIBp5w5o ydaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=hTvcC4x4nkGZQkTbFcNmtsBXR1OfB93MFgFMljHxXKU=; b=jkshdC8l7KjNAJpK0ZyaA7Z4UmjipdpcteE4/2KC7wOU5GgoV4ErhwJfEva5jq8buB psP1ZAdBdBVOlF8izSsQ43ry7O7X/XENTNqKkdss3WxSEXIAP4cYfOcnRaKwJ3lRwWZz Nbv+03AgET9eUxv+MPkwS8a8IcC7puj9dilylo9onUqznerMOFTNL9B/3FRjQyQrJjLR kXCcWDEtqD9SWCUnPibXFbCRcffSmC7zimKh1n4pzZp8bGldYYgapKlepjf8IjDpzy/a tp/KRhWYHmm8GUxcr9OWvQ0X9T1vaLH4CNXTK2FL/+XLs0xa8D3bdxciOhnASNm3X7HY NiOw== X-Gm-Message-State: AG10YORxKQagliDE4PVmiFK/07dZohlRJ2egC10+fTO7SKAZgknBlZ3qTHekpuLF+lbMVizBd26xAnvOu3MPrg== MIME-Version: 1.0 X-Received: by 10.25.158.136 with SMTP id h130mr9138909lfe.136.1453832063990; Tue, 26 Jan 2016 10:14:23 -0800 (PST) Sender: rizzo.unipi@gmail.com Received: by 10.114.4.232 with HTTP; Tue, 26 Jan 2016 10:14:23 -0800 (PST) In-Reply-To: <20160126182543.64050678@ernst.home> References: <20160118140811.GW3942@kib.kiev.ua> <20160120073154.GB3942@kib.kiev.ua> <20160121093509.GK3942@kib.kiev.ua> <20160121233040.E1864@besplex.bde.org> <20160124050634.GS3942@kib.kiev.ua> <20160124100747.551f8e3f@ernst.home> <20160126134005.GD3942@kib.kiev.ua> <20160126182543.64050678@ernst.home> Date: Tue, 26 Jan 2016 10:14:23 -0800 X-Google-Sender-Auth: TjSAZi3JKdgjk9-9NQ8aEuFCRPk Message-ID: Subject: Re: Does FreeBSD have sendmmsg or recvmmsg system calls? From: Luigi Rizzo To: gljennjohn@gmail.com Cc: Konstantin Belousov , Boris Astardzhiev , threads@freebsd.org, "freebsd-net@freebsd.org" Content-Type: text/plain; charset=UTF-8 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: Tue, 26 Jan 2016 18:14:26 -0000 On Tue, Jan 26, 2016 at 9:25 AM, Gary Jennejohn wrote: > On Tue, 26 Jan 2016 09:06:39 -0800 > Luigi Rizzo wrote: > >> On Tue, Jan 26, 2016 at 5:40 AM, Konstantin Belousov >> wrote: >> > On Mon, Jan 25, 2016 at 11:22:13AM +0200, Boris Astardzhiev wrote: >> >> +ssize_t >> >> +recvmmsg(int s, struct mmsghdr *__restrict msgvec, size_t vlen, int flags, >> >> + const struct timespec *__restrict timeout) >> >> +{ >> >> + size_t i, rcvd; >> >> + ssize_t ret; >> >> + >> >> + if (timeout != NULL) { >> >> + fd_set fds; >> >> + int res; >> > Please move all local definitions to the beginning of the function. >> >> This style recommendation was from 30 years ago and is >> bad programming practice, as it tends to complicate analysis >> for the human and increase the chance of improper usage of >> variables. >> >> We should move away from this for new code. >> > > Really? I personally find having all variables grouped together > much easier to understand. Stumbling across declarations in the > middle of the code in a for-loop, for example, takes me by surprise. > > I also greatly dislike initializing variables in their declarations. > > Maybe I'm just old fashioned since I have been writing C-code for > more than 30 years. (sorry for the digression) I am in the same ballpark in terms of coding age, but systems have become a lot more complex in that time window, code size generally exploded, and compilers are smarter so they do not need hints from the programmer on when to do initializations, or stack reuse or register allocations. I find that reducing the scope of variables helps a lot understanding third party code (e.g. where information belongs to) and reduces the chance of misuse (such as, leaking information from the body of a loop). About initializers in declarations, I think the rule should be "use good judgement and privilege readability". E.g., do postpone initialization if the first use is 20 lines down, so that it is clear what the value is by the time you use the variable; or when there is some complex condition to check, as writing it as a conditional expression may be ugly and cause code duplication and lead to poor error handling. But when the first use is close to the declaration, splitting the initialization is just unnecessary source bloat. cheers luigi > > -- > Gary Jennejohn -- -----------------------------------------+------------------------------- Prof. Luigi RIZZO, rizzo@iet.unipi.it . Dip. di Ing. dell'Informazione http://www.iet.unipi.it/~luigi/ . Universita` di Pisa TEL +39-050-2217533 . via Diotisalvi 2 Mobile +39-338-6809875 . 56122 PISA (Italy) -----------------------------------------+-------------------------------