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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It works very similarly to
send(): if the socket is set asO_NONBLOCKand the operation would block,sendfile()returns immediately and setserrnotoEAGAIN. In this case you have to wait a while and then try again (maybe using a function likeselect()to know when it’s ready).Also keep in mind that even if it succeeds it may not write all the bytes you requested in a single function call. Always check the return value:
You can also take a look at the man page for sendfile()