fix bugs in sending messages through sockets (4.4BSD-alpha/sys/6)
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Sun, 28 Feb 1993 15:16:35 +0000 (07:16 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Sun, 28 Feb 1993 15:16:35 +0000 (07:16 -0800)
SCCS-vsn: sys/kern/uipc_socket.c 7.38
SCCS-vsn: sys/kern/uipc_syscalls.c 7.29

usr/src/sys/kern/uipc_socket.c
usr/src/sys/kern/uipc_syscalls.c

index 1fe0828..5ab3baa 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)uipc_socket.c       7.37 (Berkeley) %G%
+ *     @(#)uipc_socket.c       7.38 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -455,6 +455,7 @@ soreceive(so, paddr, uio, mp0, controlp, flagsp)
        struct protosw *pr = so->so_proto;
        struct mbuf *nextrecord;
        int moff, type;
        struct protosw *pr = so->so_proto;
        struct mbuf *nextrecord;
        int moff, type;
+       int orig_resid = uio->uio_resid;
 
        mp = mp0;
        if (paddr)
 
        mp = mp0;
        if (paddr)
@@ -556,6 +557,7 @@ restart:
                if (m->m_type != MT_SONAME)
                        panic("receive 1a");
 #endif
                if (m->m_type != MT_SONAME)
                        panic("receive 1a");
 #endif
+               orig_resid = 0;
                if (flags & MSG_PEEK) {
                        if (paddr)
                                *paddr = m_copy(m, 0, m->m_len);
                if (flags & MSG_PEEK) {
                        if (paddr)
                                *paddr = m_copy(m, 0, m->m_len);
@@ -594,8 +596,10 @@ restart:
                                m = so->so_rcv.sb_mb;
                        }
                }
                                m = so->so_rcv.sb_mb;
                        }
                }
-               if (controlp)
+               if (controlp) {
+                       orig_resid = 0;
                        controlp = &(*controlp)->m_next;
                        controlp = &(*controlp)->m_next;
+               }
        }
        if (m) {
                if ((flags & MSG_PEEK) == 0)
        }
        if (m) {
                if ((flags & MSG_PEEK) == 0)
@@ -703,18 +707,27 @@ restart:
                        }
                }
        }
                        }
                }
        }
+
+       if (m && pr->pr_flags & PR_ATOMIC) {
+               flags |= MSG_TRUNC;
+               if ((flags & MSG_PEEK) == 0)
+                       (void) sbdroprecord(&so->so_rcv);
+       }
        if ((flags & MSG_PEEK) == 0) {
                if (m == 0)
                        so->so_rcv.sb_mb = nextrecord;
        if ((flags & MSG_PEEK) == 0) {
                if (m == 0)
                        so->so_rcv.sb_mb = nextrecord;
-               else if (pr->pr_flags & PR_ATOMIC) {
-                       flags |= MSG_TRUNC;
-                       (void) sbdroprecord(&so->so_rcv);
-               }
                if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
                        (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,
                            (struct mbuf *)flags, (struct mbuf *)0,
                            (struct mbuf *)0);
        }
                if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
                        (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,
                            (struct mbuf *)flags, (struct mbuf *)0,
                            (struct mbuf *)0);
        }
+       if (orig_resid == uio->uio_resid && orig_resid &&
+           (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
+               sbunlock(&so->so_rcv);
+               splx(s);
+               goto restart;
+       }
+               
        if (flagsp)
                *flagsp |= flags;
 release:
        if (flagsp)
                *flagsp |= flags;
 release:
index 519ee1d..95cd9e5 100644 (file)
@@ -2,7 +2,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)uipc_syscalls.c     7.28 (Berkeley) %G%
+ *     @(#)uipc_syscalls.c     7.29 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -758,7 +758,8 @@ recvit(p, s, mp, namelenp, retsize)
 #endif
        len = auio.uio_resid;
        if (error = soreceive((struct socket *)fp->f_data, &from, &auio,
 #endif
        len = auio.uio_resid;
        if (error = soreceive((struct socket *)fp->f_data, &from, &auio,
-           (struct mbuf **)0, &control, &mp->msg_flags)) {
+           (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
+           &mp->msg_flags)) {
                if (auio.uio_resid != len && (error == ERESTART ||
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;
                if (auio.uio_resid != len && (error == ERESTART ||
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;