C
Chris McDonald
[hopefully of wide interest, and not too OT]
Under Linux, I'm using select() to detect when any of a collection of
socket descriptors is ready for reading. Associated with each socket
descriptor is a FILE pointer, obtained via fdopen(sd, "r"). When any
socket descriptor becomes ready, I call fgets(...., fp) to read a line
of textual input.
However, I suspect that if more than one line of input is ready on the
socket descriptor, that fgets() reads it all in and places it in the
stdio buffer associated with the FILE pointer. Thus, I'm not able to
tell when the "2nd" line of input arrives, because the socket descriptor
is not ready, and the 2nd line has already arrived, and is sitting in
the FILE's buffer.
How can I tell if anything resides in the FILE's buffer, without
performing another blocking fgets() ?
Thanks,
_______________________________________________________________________________
Dr Chris McDonald E: (e-mail address removed)
Computer Science & Software Engineering W: http://www.csse.uwa.edu.au/~chris
The University of Western Australia, M002 T: +618 6488 2533
Crawley, Western Australia, 6009 F: +618 6488 1089
Under Linux, I'm using select() to detect when any of a collection of
socket descriptors is ready for reading. Associated with each socket
descriptor is a FILE pointer, obtained via fdopen(sd, "r"). When any
socket descriptor becomes ready, I call fgets(...., fp) to read a line
of textual input.
However, I suspect that if more than one line of input is ready on the
socket descriptor, that fgets() reads it all in and places it in the
stdio buffer associated with the FILE pointer. Thus, I'm not able to
tell when the "2nd" line of input arrives, because the socket descriptor
is not ready, and the 2nd line has already arrived, and is sitting in
the FILE's buffer.
How can I tell if anything resides in the FILE's buffer, without
performing another blocking fgets() ?
Thanks,
_______________________________________________________________________________
Dr Chris McDonald E: (e-mail address removed)
Computer Science & Software Engineering W: http://www.csse.uwa.edu.au/~chris
The University of Western Australia, M002 T: +618 6488 2533
Crawley, Western Australia, 6009 F: +618 6488 1089