When does the write() system call write all of the requested buffer versus just doing a partial write?

后端 未结 3 663
无人及你
无人及你 2021-02-09 21:55

If I am counting on my write() system call to write say e.g., 100 bytes, I always put that write() call in a loop that checks to see if the length that gets returned is what I e

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-09 22:28

    Writes shouldn't have any reason to ever write a partial buffer afaik. Possible reasons I could think of for a partial write is if you run out of disk space, you're writing past the end of a block device, or if you're writing to a char device / some other sort of device.

    However, the plan to retry writes blindly is probably not such a good one - check errno to see whether you should be retrying first.

提交回复
热议问题