Date: Fri, 06 Nov 1998 08:03:44 -0800 From: David Greenman <dg@root.com> To: Matthew Dillon <dillon@apollo.backplane.com> Cc: cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG Subject: Re: sendfile.2 (was Re: cvs commit: ...) Message-ID: <199811061603.IAA18481@implode.root.com> In-Reply-To: Your message of "Thu, 05 Nov 1998 18:56:46 PST." <199811060256.SAA00345@apollo.backplane.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Matt, please try out the attached patches that provide non-blocking support for sendfile(2). It works like this: If the socket is set non-blocking, then sendfile(2) will send as much as it can and if there is still more to send, it will return EAGAIN and return the number of bytes written to the socket in *sbytes. The application will need to keep track of the number of bytes written and adjust the file offset accordingly for subsequant sendfile(2) calls. Further, if headers/trailers are specified, then the application will need to figure out the mess and rebuild the iovecs as appropriate. -DG David Greenman Co-founder/Principal Architect, The FreeBSD Project Index: uipc_syscalls.c =================================================================== RCS file: /home/ncvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.42 diff -c -r1.42 uipc_syscalls.c *** uipc_syscalls.c 1998/11/05 14:28:24 1.42 --- uipc_syscalls.c 1998/11/06 15:55:30 *************** *** 1506,1511 **** --- 1506,1523 ---- if (xfsize <= 0) break; /* + * Optimize the non-blocking case by looking at the socket space + * before going to the extra work of constituting the sf_buf. + */ + if ((so->so_state & SS_NBIO) && sbspace(&so->so_snd) <= 0) { + if (so->so_state & SS_CANTSENDMORE) + error = EPIPE; + else + error = EAGAIN; + sbunlock(&so->so_snd); + goto done; + } + /* * Attempt to look up the page. If the page doesn't exist or the * part we're interested in isn't valid, then read it from disk. * If some other part of the kernel has this page (i.e. it's busy), *************** *** 1634,1639 **** --- 1646,1658 ---- * a race condition with sbwait(). */ if (sbspace(&so->so_snd) <= 0) { + if (so->so_state & SS_NBIO) { + m_freem(m); + sbunlock(&so->so_snd); + splx(s); + error = EAGAIN; + goto done; + } error = sbwait(&so->so_snd); /* * An error from sbwait usually indicates that we've To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811061603.IAA18481>