write() may write fewer bytes than requested, and since this is not

an error, we should retry until all bytes have been written.