On Mon, 29 Mar 1999, Justin Georgeson wrote:
> How do I do this using the BSD sockets model? My program hangs on the
> read command and I think it's because the write command didn't flush the
> buffer. Thanks.
read() and write() will return the actual number of bytes written. To
ensure a flush, you have to write code like this:
char *data_to_write;
int number_of_bytes,r;
while (number_of_bytes) {
r = write(fd,data_to_write,number_of_bytes);
if (r == -1) {
/* handle error */
}
data_to_write += r;
number_of_bytes -= r;
}
Note, however, that blocking sockets _usually_ do not return r <
number_of_bytes. However, it is possible on devices and sockets for this
to happen. (RealPlayer has a bug on my machine which prevents it playing
audio for this reason.)
Taral
---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]