* Alfred Perlstein <[EMAIL PROTECTED]> [011213 12:08] wrote:
> * Bruce Evans <[EMAIL PROTECTED]> [011213 05:56] wrote:
> > 
> > >From POSIX.1-200x-draft7 (this has not changed since at least the 1990
> > version):
> > 
> > ! 36609              When attempting to read from an empty pipe or FIFO:
> > !
> > ! 36610                * If no process has the pipe open for writing, read( ) 
>shall return 0 to indicate end-of-file.
> > 
> > The changes make read() block instead, at least for the non-O_NONBLOCK case.
> > I'm not sure of the effect of the change in the O_NONBLOCK case, but it
> > seems likely that -1/EAGAIN is returned instead of 0/no-error.
> 
> Ok, I can fix this.  (I hope :) )

Can people take a look at this fix?  It seems to dtrt, but I need feedback
here.

It basically backs out my last two revisions and changes the hacks the
poll call to seemingly do the right thing.


Index: fifo_vnops.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/fifofs/fifo_vnops.c,v
retrieving revision 1.57
diff -u -r1.57 fifo_vnops.c
--- fifo_vnops.c        12 Dec 2001 09:35:33 -0000      1.57
+++ fifo_vnops.c        15 Dec 2001 21:25:30 -0000
@@ -199,6 +199,7 @@
                }
                fip->fi_readers = fip->fi_writers = 0;
                wso->so_snd.sb_lowat = PIPE_BUF;
+               rso->so_state |= SS_CANTRCVMORE;
        }
        if (ap->a_mode & FREAD) {
                fip->fi_readers++;
@@ -283,11 +284,6 @@
        VOP_UNLOCK(ap->a_vp, 0, td);
        error = soreceive(rso, (struct sockaddr **)0, uio, (struct mbuf **)0,
            (struct mbuf **)0, (int *)0);
-       /*
-        * Clear EOF indication after first such return.
-        */
-       if (uio->uio_resid == startresid)
-               rso->so_state &= ~SS_CANTRCVMORE;
        vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY, td);
        if (ap->a_ioflag & IO_NDELAY)
                rso->so_state &= ~SS_NBIO;
@@ -455,13 +451,23 @@
        } */ *ap;
 {
        struct file filetmp;
-       int revents = 0;
+       int s, revents = 0;
 
        if (ap->a_events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) {
+               struct socket *so;
+               int oflg;
+
                filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
+               so = (struct socket *)filetmp.f_data;
+               s = splnet();
+               oflg = so->so_state & SS_CANTRCVMORE;
+               if (ap->a_vp->v_fifoinfo->fi_writers == 0)
+                       so->so_state &= ~SS_CANTRCVMORE;
                if (filetmp.f_data)
                        revents |= soo_poll(&filetmp, ap->a_events, ap->a_cred,
                            ap->a_td);
+               so->so_state |= oflg;
+               splx(s);
        }
        if (ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND)) {
                filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-net" in the body of the message

Reply via email to