From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 2 21:45:17 2011 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C7CC0106564A for ; Tue, 2 Aug 2011 21:45:17 +0000 (UTC) (envelope-from dudu@dudu.ro) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id 6053A8FC15 for ; Tue, 2 Aug 2011 21:45:17 +0000 (UTC) Received: by fxe4 with SMTP id 4so322840fxe.13 for ; Tue, 02 Aug 2011 14:45:16 -0700 (PDT) Received: by 10.223.159.4 with SMTP id h4mr1666328fax.57.1312321516223; Tue, 02 Aug 2011 14:45:16 -0700 (PDT) Received: from [192.168.10.3] ([82.76.253.74]) by mx.google.com with ESMTPS id x20sm116126fah.2.2011.08.02.14.45.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 02 Aug 2011 14:45:14 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1244.3) Content-Type: text/plain; charset=us-ascii From: Vlad Galu In-Reply-To: <20110802211652.GA28731@stack.nl> Date: Tue, 2 Aug 2011 23:45:11 +0200 Content-Transfer-Encoding: 7bit Message-Id: References: <7E99FCF5-66DF-422E-B2FE-28547AF916A7@dudu.ro> <20110802211652.GA28731@stack.nl> To: Jilles Tjoelker X-Mailer: Apple Mail (2.1244.3) Cc: hackers@freebsd.org Subject: Re: eliminating a syscall on accept()+ioctl() combo X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2011 21:45:17 -0000 On Aug 2, 2011, at 11:16 PM, Jilles Tjoelker wrote: > On Mon, Aug 01, 2011 at 08:11:04AM +0200, Vlad Galu wrote: >> On Jul 31, 2011, at 9:59 PM, Bernard van Gastel wrote: >>> I want to reduce the number of syscalls for my networking >>> application. The app handles incoming connections with the >>> 'accept()' system call. Is there a way to specify to accept() that >>> the newly created file descriptors should be non-blocking (FIONBIO)? >>> This will avoid an ioctl() after the accept(). Thanks! > >> You can make your listening socket non-blocking. Newly created file >> descriptors will inherit that property. However, that will require you >> to select()/poll()/kqueue() for that descriptor as well, instead of >> simply blocking in accept(). > > This is documented FreeBSD behaviour and common across BSDs, but is not > portable. POSIX leaves it unspecified what the non-blocking state of the > new socket is and in fact Linux always makes the new socket blocking > (unless you request non-blocking using their new accept4() call). > > Because this portability issue can be very subtle, I suggest not blindly > relying on it. Oh, ok. I wasn't aware. Thanks for the heads-up. Good, fast & cheap: pick any two.