cservererrnosendfile

Why does sendfile not check if reading from the input descriptor would block?


As a server, I want to read from a non-blocking client socket and then write to a file.

According to the man page for sendfile, if errno is set to EAGAIN, then this only signals that, if the output file descriptor is set to be non-blocking, then a call to sendfile would block.

That is, the underlying call that sendfile makes to write would block.

Is there anyway to use sendfile so that errno is EAGAIN if reading would block?


Solution

  • Certainly.

    Using the select() library function with your read descriptor, you can check for EWOULDBLOCK via errno. If it is set, then the read would block.

    You cannot see if the read would block by checking something on your sendfile() call.