From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 8 02:50:48 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 84FDD1065670 for ; Fri, 8 Aug 2008 02:50:48 +0000 (UTC) (envelope-from unixmania@gmail.com) Received: from mu-out-0910.google.com (mu-out-0910.google.com [209.85.134.187]) by mx1.freebsd.org (Postfix) with ESMTP id 098678FC15 for ; Fri, 8 Aug 2008 02:50:47 +0000 (UTC) (envelope-from unixmania@gmail.com) Received: by mu-out-0910.google.com with SMTP id i2so637390mue.3 for ; Thu, 07 Aug 2008 19:50:46 -0700 (PDT) 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=+E5L0PgI/J7fCBG90OLkzp7EWonNQO1NzFNVyJ1jc30=; b=exSqv1k/8RERYBwi1m69aCMVTbQlIWtUnzXgqeLH0mN7KHHPXjFCofE+ZSNLBChXjn qHIdJbQO/32smUiCsGgWiTD7JlI2FiZ0T2rXChmEajcSVahRyWEsl4gJz3okri7On+OZ MZldGuLCrJPGWNvUgKtnLY3vdm7Cp1EHhFVu8= 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=iq+HuH8Xa3vUj5kyGba2+EfSSkCuh37iWAtIy6Q1K22bNFMNxbqYMch19nwGnoCOCC b9PhzzO+RfRvqG/Dsaf0YqTfOVNDXJmOWj/rSNaI2DAoB2pYYD0N1Nq7cvTp4tXFDZkk S+P8SaUJeLyTgeCrRhz9Q4OE2jKLOgLhosrdk= Received: by 10.103.238.4 with SMTP id p4mr2634400mur.66.1218163845283; Thu, 07 Aug 2008 19:50:45 -0700 (PDT) Received: by 10.103.169.13 with HTTP; Thu, 7 Aug 2008 19:50:45 -0700 (PDT) Message-ID: Date: Thu, 7 Aug 2008 23:50:45 -0300 From: "Carlos A. M. dos Santos" To: "Chuck Robey" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <489B9D4D.4010009@telenix.org> Cc: Nate Eldredge , FreeBSD-Hackers 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 02:50:48 -0000 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. -- If you think things can't get worse it's probably only because you lack sufficient imagination.