Added support for non-blocking sockets to sendfile(2).

This commit is contained in:
dg 1998-11-06 19:16:30 +00:00
parent 053db512ad
commit fc0d420464

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
* $Id: uipc_syscalls.c,v 1.41 1998/08/23 03:06:59 wollman Exp $
* $Id: uipc_syscalls.c,v 1.42 1998/11/05 14:28:24 dg Exp $
*/
#include "opt_compat.h"
@ -1505,6 +1505,18 @@ sendfile(struct proc *p, struct sendfile_args *uap)
xfsize = uap->nbytes - sbytes;
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.
@ -1634,6 +1646,13 @@ sendfile(struct proc *p, struct sendfile_args *uap)
* 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