From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 27 18:43:17 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 6C2351065673 for ; Wed, 27 Feb 2008 18:43:17 +0000 (UTC) (envelope-from mark.linn@gmail.com) Received: from ti-out-0910.google.com (ti-out-0910.google.com [209.85.142.190]) by mx1.freebsd.org (Postfix) with ESMTP id F3F218FC25 for ; Wed, 27 Feb 2008 18:43:16 +0000 (UTC) (envelope-from mark.linn@gmail.com) Received: by ti-out-0910.google.com with SMTP id j2so2255565tid.3 for ; Wed, 27 Feb 2008 10:43:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=68a3Wd+OSYAE1gtU65L+xyRAs/YPi9V+SbjJmX50b9I=; b=BXJEZFf5n60Ww3YkWEDReElnKtlEO4tjYbHYc7rM7pjfHuucTa97qIut2A0e0aq7OVneSGgU43tIe9V03sw4RlIAUK8Oji9+Rx25O4CZxHs87Ta8hbBN7oQ7Fz6gQskGfxXUYnvpyxvrO3LwHZL9lAuDy+3qAHJGo1hM1dhtzfs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=yFXBNhXpmSKZOlVzpNXCyPtc6QMCTfSy0yGy4GdXBQGqTTcv6vyJDiU0uwXR7EZE34Y2v/8Wu6ke5mhTHEduJTjld1rMX1hQQeORz9DQBZZHkeNqifNZWLAfIHCvQKGCklmo8HEATXxzB5/4YO1X0B7vRt4rUHdy65tHP2JFTjI= Received: by 10.150.191.10 with SMTP id o10mr2433154ybf.84.1204137793535; Wed, 27 Feb 2008 10:43:13 -0800 (PST) Received: by 10.150.226.21 with HTTP; Wed, 27 Feb 2008 10:43:13 -0800 (PST) Message-ID: <84fb42ef0802271043n1f5d8318ie259b7b4e9622c1d@mail.gmail.com> Date: Wed, 27 Feb 2008 10:43:13 -0800 From: "Mark Linn" To: "James Bailie" In-Reply-To: <47C564B6.10906@mammothcheese.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <84fb42ef0802270107y4ddb8fd2scd83fe086414869f@mail.gmail.com> <47C564B6.10906@mammothcheese.ca> Cc: freebsd-hackers@freebsd.org 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 18:43:17 -0000 On Wed, Feb 27, 2008 at 5:25 AM, James Bailie wrote: > 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 > Thanks, Ed and James, Then why in the world the sample code in this acm paper would test EINTR in read and write? link is here. http://delivery.acm.org/10.1145/1350000/1344155/9815.html?key1=1344155&key2=2950393021&coll=GUIDE&dl=&CFID=15151515&CFTOKEN=6184618