Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 08 Aug 2008 16:30:49 -0400
From:      Chuck Robey <chuckr@telenix.org>
To:        "Carlos A. M. dos Santos" <unixmania@gmail.com>
Cc:        Pieter de Goeje <pieter@degoeje.nl>, freebsd-standards@freebsd.org, freebsd-hackers@freebsd.org
Subject:   Re: read with timeout ??
Message-ID:  <489CACF9.3030309@telenix.org>
In-Reply-To: <e71790db0808080733p132180e9wba33d5840e1b954f@mail.gmail.com>
References:  <489B9D4D.4010009@telenix.org>	<Pine.GSO.4.64.0808071813530.11980@zeno.ucsd.edu>	<e71790db0808071950j32e196e4o42fab1aeb62ab8a4@mail.gmail.com>	<200808081009.56521.pieter@degoeje.nl> <e71790db0808080733p132180e9wba33d5840e1b954f@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carlos A. M. dos Santos wrote:
> On Fri, Aug 8, 2008 at 5:09 AM, Pieter de Goeje <pieter@degoeje.nl> 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.
> 
> BTW, the setsockopt(2) manual page stands that a send or receive
> timeout returns with the error EWOULDBLOCK but read(2) recv(2) send(2)
> and write(2) only list EAGAIN in their ERRORS section. This is
> harmless on BSD and Linux because EAGAIN and EWOULDBLOCK are the same,
> but may sound confusing for people porting from/to System V. On HP-UX,
> for instance, recv(2) lists both EAGAIN and EWOULDBLOCK.
> 
> The setsockopt man page should be improved in order to explain
> standards conformance and porting issues. I volunteer to do it but the
> changes must be reviewed by a native English speaker.
> 

Carlos, lets not go off on the socket trip for me... while I personally enjoy
such a email, I have to admit my own needs fall more into a plain-jame serial
line, nothing a socket-oriented thing could help me with.

However, if you want to discuss this just fo the fun of it, oh please, by all
means do carry on!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkicrPkACgkQz62J6PPcoOmJowCfWPt1jHY4Gx0kOAQedVATHYDd
BGYAoJe6JYuskZZe85AA63sgRBG1VGF0
=dNTn
-----END PGP SIGNATURE-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?489CACF9.3030309>