read with timeout ??
Pieter de Goeje
pieter at degoeje.nl
Fri Aug 8 08:10:17 UTC 2008
On Friday 08 August 2008, Carlos A. M. dos Santos wrote:
> On Thu, Aug 7, 2008 at 10:14 PM, Nate Eldredge <neldredge at 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.
--
Pieter de Goeje
More information about the freebsd-hackers
mailing list