From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 8 08:10: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 28CFB10656F3 for ; Fri, 8 Aug 2008 08:10:17 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from mx.utwente.nl (unknown [IPv6:2001:610:1908:1000:204:23ff:feb7:b8fe]) by mx1.freebsd.org (Postfix) with ESMTP id 27AA88FC19 for ; Fri, 8 Aug 2008 08:10:15 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from lux.student.utwente.nl (lux.student.utwente.nl [130.89.170.81]) by mx.utwente.nl (8.12.10/SuSE Linux 0.7) with ESMTP id m7889uDf003188; Fri, 8 Aug 2008 10:09:57 +0200 From: Pieter de Goeje To: freebsd-hackers@freebsd.org Date: Fri, 8 Aug 2008 10:09:55 +0200 User-Agent: KMail/1.9.7 References: <489B9D4D.4010009@telenix.org> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200808081009.56521.pieter@degoeje.nl> X-UTwente-MailScanner-Information: Scanned by MailScanner. Contact servicedesk@icts.utwente.nl for more information. X-UTwente-MailScanner: Found to be clean X-UTwente-MailScanner-From: pieter@degoeje.nl X-Spam-Status: No Cc: "Carlos A. M. dos Santos" , Nate Eldredge , Chuck Robey 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Aug 2008 08:10:17 -0000 On Friday 08 August 2008, Carlos A. M. dos Santos wrote: > On Thu, Aug 7, 2008 at 10:14 PM, Nate Eldredge 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. -- Pieter de Goeje