From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 27 13:51:52 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60EF51065673 for ; Wed, 27 Feb 2008 13:51:52 +0000 (UTC) (envelope-from jimmy@mammothcheese.ca) Received: from smtp103.rog.mail.re2.yahoo.com (smtp103.rog.mail.re2.yahoo.com [206.190.36.81]) by mx1.freebsd.org (Postfix) with SMTP id F08E08FC1E for ; Wed, 27 Feb 2008 13:51:51 +0000 (UTC) (envelope-from jimmy@mammothcheese.ca) Received: (qmail 38494 invoked from network); 27 Feb 2008 13:25:11 -0000 Received: from unknown (HELO ?99.250.61.49?) (jazzturk@rogers.com@99.250.61.49 with plain) by smtp103.rog.mail.re2.yahoo.com with SMTP; 27 Feb 2008 13:25:11 -0000 X-YMail-OSG: BbV2udAVM1mWYlWcJ7u4re1vJoZluGi2g6YnUmaeK6Bc_BgO5r1x8CYLl4.eeo_m_g-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <47C564B6.10906@mammothcheese.ca> Date: Wed, 27 Feb 2008 08:25:10 -0500 From: James Bailie User-Agent: Thunderbird 2.0.0.9 (X11/20080123) MIME-Version: 1.0 To: Mark Linn , freebsd-hackers@freebsd.org References: <84fb42ef0802270107y4ddb8fd2scd83fe086414869f@mail.gmail.com> In-Reply-To: <84fb42ef0802270107y4ddb8fd2scd83fe086414869f@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Re: non-blocking io, EINTR 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: Wed, 27 Feb 2008 13:51:52 -0000 Mark Linn wrote: > I am setting the O_NONBLOCK flag on a socket file descriptor using fcntl, > > will a read() on the socket return EINTR when the process get a signal? By default, read() will restart itself automatically, regardless of whether the socket is blocking or not, as long as there is data to be read in the socket receive buffer. You can change this behavior by calling sigaction(). For example, the code below will make SIGTERM interrupt system calls. They will return an error code, usually -1, with the global errno set to EINTR. If the socket is non-blocking and the socket receive buffer is empty, then read() will also return an error, but with errno set to EWOULDBLOCK. #include struct sigaction sigact; sigact.sa_handler = sigterm_handler; sigemptyset( &sigact.sa_mask ); sigact.sa_flags = 0; if ( sigaction( SIGTERM, &sigact, NULL ) < 0 ) { perror( "sigaction()" ); exit( 1 ); } -- James Bailie http://www.mammothcheese.ca