From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 2 21:16:54 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 C7B31106566C for ; Tue, 2 Aug 2011 21:16:54 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 66EF98FC13 for ; Tue, 2 Aug 2011 21:16:54 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id EB7073593B0; Tue, 2 Aug 2011 23:16:52 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id E0FFF17431; Tue, 2 Aug 2011 23:16:52 +0200 (CEST) Date: Tue, 2 Aug 2011 23:16:52 +0200 From: Jilles Tjoelker To: Vlad Galu Message-ID: <20110802211652.GA28731@stack.nl> References: <7E99FCF5-66DF-422E-B2FE-28547AF916A7@dudu.ro> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7E99FCF5-66DF-422E-B2FE-28547AF916A7@dudu.ro> User-Agent: Mutt/1.5.21 (2010-09-15) 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:16:54 -0000 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. -- Jilles Tjoelker