Linux and sendfile

Kevin D. Clark kclark at CetaceanNetworks.com
Tue Oct 29 18:14:09 EST 2002


[PLEASE DON'T TOPQUOTE]


Jeff Macdonald <jeff.macdonald at virtualbuilder.com> writes:

> out_fd is a socket
> in_fd is a file
> 
> 
> recent kernels. And you've guessed it, I want to use non-blocking mode
> on the sockets (tcp).
> 
> basically I'm using sendfile to send the data portion of a SMTP session.
> Since that may take a while, I'd like to do it in non-blocking mode. I
> just read stevens APUE about O_NONBLOCK and for write I could get fewer
> bytes then requested (page 365). So can I expect the same behavior from
> sendfile?

I wouldn't depend on sendfile() returning -1 and setting errno to
EWOULDBLOCK (it doesn't seem to) when out_fd is in non-blocking
mode, but still, you can proceed if your code pays attention to the
number of bytes written.

Your code should select()/poll()/whatever on out_fd() and when there
is room to write, you should call sendfile() with the appropiate
arguments.

(does sendfile() block on in_fd?  I don't think so.  It seems to read
the data if it is already in cache, but doesn't hang around and block
waiting for the page to arrive if it's not already there)

Regards,

--kevin
-- 
Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA)
cetaceannetworks.com!kclark (GnuPG ID: B280F24E)
alumni.unh.edu!kdc




More information about the gnhlug-discuss mailing list