Re: read with timeout ??
On Friday 08 August 2008, Carlos A. M. dos Santos wrote: On Thu, Aug 7, 2008 at 10:14 PM, Nate Eldredge [EMAIL PROTECTED] 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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: read with timeout ??
On Fri, Aug 8, 2008 at 5:09 AM, Pieter de Goeje [EMAIL PROTECTED] wrote: On Friday 08 August 2008, Carlos A. M. dos Santos wrote: On Thu, Aug 7, 2008 at 10:14 PM, Nate Eldredge [EMAIL PROTECTED] 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. -- If you think things can't get worse it's probably only because you lack sufficient imagination. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: read with timeout ??
-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 [EMAIL PROTECTED] 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- ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: read with timeout ??
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Carlos A. M. dos Santos wrote: On Fri, Aug 8, 2008 at 5:09 AM, Pieter de Goeje [EMAIL PROTECTED] wrote: On Friday 08 August 2008, Carlos A. M. dos Santos wrote: On Thu, Aug 7, 2008 at 10:14 PM, Nate Eldredge [EMAIL PROTECTED] 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- ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: read with timeout ??
On Fri, 8 Aug 2008, Chuck Robey wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Pieter de Goeje wrote: 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. AFAIK the effects are identical, just the arguments are set up in a different way. Both of them will block until the fd is ready and then return immediately (subject to other processes running of course). The name poll is a misnomer because it doesn't actually work by polling, but you can pretend that it does (and does so infinitely often). Neither one uses signals per se, though if the underlying hardware device is interrupt-driven, that will be what (indirectly) triggers the wake-up. poll does seem to be more convenient than messing about with fd_set's. select is older and so it comes to my mind first, that's all. -- Nate Eldredge [EMAIL PROTECTED] ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: read with timeout ??
On 2008-Aug-08 16:30:49 -0400, Chuck Robey [EMAIL PROTECTED] wrote: 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. If this is a normal serial port then termios(4) might help: Use non-canonical processing with VMIN = 0 and VTIME = 10 (see the section Noncanonical Mode Input Processing). -- Peter Jeremy Please excuse any delays as the result of my ISP's inability to implement an MTA that is either RFC2821-compliant or matches their claimed behaviour. pgpuhtxg3EmOZ.pgp Description: PGP signature
read with timeout ??
-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. I just wouldn't like to come up with 4 pounds of code where it ought to be done with a 1-liner. If you're curious, I'm still working on that tablet driver for FreeBSD. It's taken me this long to figure out that Xorg driver code. The Xorg folks have been helpful, but basically, there's almost no docs, nearly no comments, and testing a driver isn't the easiest thing in the world. Regardless, I'm getting really close on this, finally. Thanks -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkibnQoACgkQz62J6PPcoOlIaQCdG5R0p0X/hXVYh/qkX/zK63/E y+EAn3ahlXnPGPzqSdVdhbx1YsEjT4qr =bA6Z -END PGP SIGNATURE- ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: read with timeout ??
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 -- Nate Eldredge [EMAIL PROTECTED] ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: read with timeout ??
On Thu, Aug 7, 2008 at 10:14 PM, Nate Eldredge [EMAIL PROTECTED] 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. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]