I'm using write
(man 2 write) to write data to a socket which has an established, blocking and very slow TCP-connection. I'm writing large chunks of data. write
returns the actual size written and of course it happens that not all data is written due to reason which are (maybe) out-of-scope of this question.
To be sure I'm encapsulating my write-call in a small loop like this:
do {
ssize_t ret = write(client, p, count);
if (ret <= 0)
break;
p += ret;
count -= ret;
} while (count);
if (count != 0)
return -ENODEV;
Is there a better way to do so, like setting a flag on the file-descriptor and thus having lower-layers handle it?