Add MSG_NBIO flag option to soreceive() and sosend() that causes

them to behave the same as if the SS_NBIO socket flag had been set
for this call.  The SS_NBIO flag for ordinary sockets is set by
fcntl(fd, F_SETFL, O_NONBLOCK).

Pass the MSG_NBIO flag to the soreceive() and sosend() calls in
fifo_read() and fifo_write() instead of frobbing the SS_NBIO flag
on the underlying socket for each I/O operation.  The O_NONBLOCK
flag is a property of the descriptor, and unlike ordinary sockets,
fifos may be referenced by multiple descriptors.
This commit is contained in:
Don Lewis 2004-06-01 01:18:51 +00:00
parent 8fb8b5fb27
commit 866046f5a6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=129911
3 changed files with 10 additions and 14 deletions

View File

@ -312,7 +312,7 @@ fifo_read(ap)
struct uio *uio = ap->a_uio;
struct socket *rso = ap->a_vp->v_fifoinfo->fi_readsock;
struct thread *td = uio->uio_td;
int error;
int error, flags;
#ifdef DIAGNOSTIC
if (uio->uio_rw != UIO_READ)
@ -320,14 +320,11 @@ fifo_read(ap)
#endif
if (uio->uio_resid == 0)
return (0);
if (ap->a_ioflag & IO_NDELAY)
rso->so_state |= SS_NBIO;
VOP_UNLOCK(ap->a_vp, 0, td);
flags = (ap->a_ioflag & IO_NDELAY) ? MSG_NBIO : 0;
error = soreceive(rso, (struct sockaddr **)0, uio, (struct mbuf **)0,
(struct mbuf **)0, (int *)0);
(struct mbuf **)0, &flags);
vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY, td);
if (ap->a_ioflag & IO_NDELAY)
rso->so_state &= ~SS_NBIO;
return (error);
}
@ -346,20 +343,17 @@ fifo_write(ap)
{
struct socket *wso = ap->a_vp->v_fifoinfo->fi_writesock;
struct thread *td = ap->a_uio->uio_td;
int error;
int error, flags;
#ifdef DIAGNOSTIC
if (ap->a_uio->uio_rw != UIO_WRITE)
panic("fifo_write mode");
#endif
if (ap->a_ioflag & IO_NDELAY)
wso->so_state |= SS_NBIO;
VOP_UNLOCK(ap->a_vp, 0, td);
flags = (ap->a_ioflag & IO_NDELAY) ? MSG_NBIO : 0;
error = sosend(wso, (struct sockaddr *)0, ap->a_uio, 0,
(struct mbuf *)0, 0, td);
(struct mbuf *)0, flags, td);
vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY, td);
if (ap->a_ioflag & IO_NDELAY)
wso->so_state &= ~SS_NBIO;
return (error);
}

View File

@ -600,7 +600,7 @@ sosend(so, addr, uio, top, control, flags, td)
snderr(EMSGSIZE);
if (space < resid + clen &&
(atomic || space < so->so_snd.sb_lowat || space < clen)) {
if (so->so_state & SS_NBIO)
if ((so->so_state & SS_NBIO) || (flags & MSG_NBIO))
snderr(EWOULDBLOCK);
sbunlock(&so->so_snd);
error = sbwait(&so->so_snd);
@ -898,7 +898,8 @@ soreceive(so, psa, uio, mp0, controlp, flagsp)
}
if (uio->uio_resid == 0)
goto release;
if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) {
if ((so->so_state & SS_NBIO) ||
(flags & (MSG_DONTWAIT|MSG_NBIO))) {
error = EWOULDBLOCK;
goto release;
}

View File

@ -393,6 +393,7 @@ struct msghdr {
#if __BSD_VISIBLE
#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
#define MSG_EOF 0x100 /* data completes connection */
#define MSG_NBIO 0x4000 /* FIONBIO mode, used by fifofs */
#define MSG_COMPAT 0x8000 /* used in sendit() */
#endif