Reputation: 192
I write about 50k bytes data to a file (which is stored in a USB disk and mount on linux 2.6.37. FAT32 ) which using O_NOBLOCK every 200 ms.Whether the write() function has any risk of returning a EAGAIN.If yes, why and in what case. I run the program already half an hour, and no error return has been reported.
Upvotes: 1
Views: 325
Reputation: 39390
Some reference, for completeness:
That aplies only to pipes; for regular files, it's ignored.
If the O_NONBLOCK flag is clear, a write request may cause the thread to block, but on normal completion it shall return nbyte.
If the O_NONBLOCK flag is set, write() requests shall be handled differently, in the following ways:
- The write() function shall not block the thread.
- A write request for {PIPE_BUF} or fewer bytes shall have the following effect: if there is sufficient space available in the pipe, write() shall transfer all the data and return the number of bytes requested. Otherwise, write() shall transfer no data and return -1 with errno set to [EAGAIN].
- A write request for more than {PIPE_BUF} bytes shall cause one of the following:
- When at least one byte can be written, transfer what it can and return the number of bytes written. When all data previously written to the pipe is read, it shall transfer at least {PIPE_BUF} bytes.
- When no data can be written, transfer no data, and return -1 with errno set to [EAGAIN].
Upvotes: 0
Reputation: 215517
Copy of correct-but-deleted answer:
No. The O_NONBLOCK
flag doesn't affect working with regular files.
Upvotes: 3