As is described in SUSv4 or POSIX.1-2008
http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html#tag_16_685_08
The write() call may return a value less than nbytes if write()ing to a NONBLOCK pipe/FIFO.
Thus, it's necessary to check the return value and write() the rest of the buffer in a loop demonstrated below:
while (bytes_to_write > 0) {
select(...); // Or poll()
retv = write(...);
if (retv < 0)
... // Error
bytes_to_write -= retv;
}
The standard says nothing about regular files, special files (aka. devices) and sockets, especially stream-based sockets (TCP sockets and UNIX Domain ones, for example).
Then, I have the following two questions:
- Will partial write() (or partial send()) possibly occur on regular files (or sockets with O_NONBLOCK unset) ?
- How about writev() and sendmsg() on NONBLOCK sockets? This is very important, since dealing with partially written vector (struct iovec []) is a bit of trouble.
Sorry for broken English.