From owner-freebsd-hackers@FreeBSD.ORG  Fri Aug  8 20:27:42 2008
Return-Path: <owner-freebsd-hackers@FreeBSD.ORG>
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 0D5371065670
	for <freebsd-hackers@freebsd.org>; Fri,  8 Aug 2008 20:27:42 +0000 (UTC)
	(envelope-from chuckr@telenix.org)
Received: from mail4.sea5.speakeasy.net (mail4.sea5.speakeasy.net
	[69.17.117.6]) by mx1.freebsd.org (Postfix) with ESMTP id DBF348FC0A
	for <freebsd-hackers@freebsd.org>; Fri,  8 Aug 2008 20:27:41 +0000 (UTC)
	(envelope-from chuckr@telenix.org)
Received: (qmail 21861 invoked from network); 8 Aug 2008 20:27:41 -0000
Received: from april.chuckr.org (HELO april.telenix.org)
	(chuckr@[66.92.151.30]) (envelope-sender <chuckr@telenix.org>)
	by mail4.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted
	SMTP for <pieter@degoeje.nl>; 8 Aug 2008 20:27:41 -0000
Message-ID: <489CAC2F.1070907@telenix.org>
Date: Fri, 08 Aug 2008 16:27:27 -0400
From: Chuck Robey <chuckr@telenix.org>
User-Agent: Thunderbird 2.0.0.6 (X11/20071107)
MIME-Version: 1.0
To: Pieter de Goeje <pieter@degoeje.nl>
References: <489B9D4D.4010009@telenix.org>
	<Pine.GSO.4.64.0808071813530.11980@zeno.ucsd.edu>
	<e71790db0808071950j32e196e4o42fab1aeb62ab8a4@mail.gmail.com>
	<200808081009.56521.pieter@degoeje.nl>
In-Reply-To: <200808081009.56521.pieter@degoeje.nl>
X-Enigmail-Version: 0.95.5
OpenPGP: id=F3DCA0E9;
	url=http://pgp.mit.edu
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Cc: "Carlos A. M. dos Santos" <unixmania@gmail.com>,
	freebsd-hackers@freebsd.org, Nate Eldredge <neldredge@math.ucsd.edu>
Subject: Re: read with timeout ??
X-BeenThere: freebsd-hackers@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Technical Discussions relating to FreeBSD
	<freebsd-hackers.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-hackers>, 
	<mailto:freebsd-hackers-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-hackers>
List-Post: <mailto:freebsd-hackers@freebsd.org>
List-Help: <mailto:freebsd-hackers-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-hackers>,
	<mailto:freebsd-hackers-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Fri, 08 Aug 2008 20:27:42 -0000

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pieter de Goeje wrote:
> On Friday 08 August 2008, Carlos A. M. dos Santos wrote:
>> On Thu, Aug 7, 2008 at 10:14 PM, Nate Eldredge <neldredge@math.ucsd.edu> 
> wrote:
>>> On Thu, 7 Aug 2008, Chuck Robey wrote:
>>>> -----BEGIN PGP SIGNED MESSAGE-----
>>>> Hash: SHA1
>>>>
>>>> I have my head lost in a code problem.  I just hit a point where I need
>>>> to do a
>>>> read from an fd, but I need to associate it with a timeout, on the order
>>>> of 1
>>>> second, something like that.  I had the feeling that there's a function
>>>> in FreeBSD's libc that makes that simple, but I forget the function
>>>> name.  If anyone can remember something like what I'm talking about, I
>>>> sure would appreciate a function name.  I can figure out how it works,
>>>> if I could only
>>>> dredge up that name.
>>> man 2 select
>> If the fd is a socket then you can also use setsockopt(2) to set
>> SO_RCVTIMEO and check for EWOULDBLOCK (same as EAGAIN) upon read(2) or
>> recv(2) errors. The net effect is the same of using select but the
>> syntax is simpler, IMO.
> 
> I think poll(2) is also simpler than select for this purpose. 
> 

It does look like that, I need to check the implementation a bit, because the
name of this thing makes me really suspicious about how often it checks for an
fd for being ready for a read.  I know select comes right back, I was under the
impression that poll didn't use signals to do this.

Anyhow, I sure do appreciate the hint, that's just exactly what I was asking
for.  Spending the time figuring it all out, that'll actually be fun for  me.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkicrC8ACgkQz62J6PPcoOmYjACfWP/IGjSvak1hLYSJwWBKkTjb
8qUAoJfSYOZcPJKMqqUb3Y1mltG51sgI
=USHT
-----END PGP SIGNATURE-----