Messages in this thread | | | Date | Fri, 12 Sep 1997 16:40:43 -0500 (CDT) | From | Jason Burrell <> | Subject | Re: how to tell if data is available for a file descriptor |
| |
On Thu, 11 Sep 1997, Geis Jerry wrote:
> > I have an open socket and a file descriptor > for that socket, how do I tell without reading the > data out of the buffer if there is data to be read? > > please CC me directly, > Thanks, > > Jerry > > I know read() tells me how many bytes were read etc... > but it also takes the bytes out of the buffer.
The select() call should be appropriate.
select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, 0);
However, I noticed what looks like an error in my manpage over here.
timeout is an upper bound on the amount of time elapsed before select returns. It may be zero, causing select to return immediately. If timeout is NULL (no timeout), select can block indefinitely.
Now from <stdio.h>:
#ifndef NULL #ifdef __cplusplus #define NULL 0 #else #define NULL (void*)0 #endif #endif
Unless I'm missing something blatently obvious, NULL == 0, and thus this manpage is nonsensical. "It may be zero, causing select to return immediately. If timeout is NULL (no timeout), select can block indefinately." How can it return immediately *and* block indefinately?
I'm confused. I've never actually used select(), as odd as that may seem to some. Well, not with indefinate or zero timeouts, anyway.
| |