Hi,
In my program, I need to check the completion of a sendfile() operation in a non-blocking socket. How can that be done?
After checking the documentation and searching on internet, I couldn't find out how to do it
Hi,
In my program, I need to check the completion of a sendfile() operation in a non-blocking socket. How can that be done?
After checking the documentation and searching on internet, I couldn't find out how to do it
It works very similarly to send()
: if the socket is set as O_NONBLOCK
and the operation would block, sendfile()
returns immediately and sets errno
to EAGAIN
.
If it does you have to wait a while and then try again (maybe using a function like select()
to know when it's ready).
Also keep in mind that even if it succeeds it may not write all the bytes you requested it to write in one function call. Always check the return value:
If the transfer was successful, the number of bytes written to out_fd is returned. On error, -1 is returned, and errno is set appropriately.
Also read the man page: link