Garrett Rooney <[EMAIL PROTECTED]> writes:
> On Fri, May 04, 2001 at 01:15:17PM -0400, Jeff Trawick wrote:
> > I noticed this weird use of sendfile() in FreeBSD's ftpd.c:
> >
> > while (err != -1 && cnt < filesize) {
> > err = sendfile(filefd, netfd, offset, len,
> > (struct sf_hdtr *) NULL, &cnt, 0);
> > byte_count += cnt;
> > offset += cnt;
> > len -= cnt;
> >
> > if (err == -1) {
> > if (!cnt)
> > goto oldway;
> >
> > goto data_err;
> > }
> > }
> >
> > I don't understand why there is a loop... (I have no idea if there is
> > a connection between the unclear need for this loop and BSD's
> > sendfile() returning 0/0...)
>
> this is just off the top of my head, but could that socket (in the ftpd code)
> be set for non-blocking io? the man page for sendfile() on freebsd indicates
> that in such a case, less than the total number of bytes could be sent, and
> EAGAIN would be returned. thus the loop.
If it were non-blocking, it would busy-loop while waiting for acks
from the client since there is no call to select or poll to wait for
writability. Extremely unlikely that such looping would go unnoticed :)
--
Jeff Trawick | [EMAIL PROTECTED] | PGP public key at web site:
http://www.geocities.com/SiliconValley/Park/9289/
Born in Roswell... married an alien...