change datagram queuing to use m_act properly; type mbufs with rights;
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 22 Aug 1984 01:43:08 +0000 (17:43 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 22 Aug 1984 01:43:08 +0000 (17:43 -0800)
change protocol family number in protosw to pointer to domain (for sam)

SCCS-vsn: sys/kern/uipc_domain.c 6.2
SCCS-vsn: sys/kern/uipc_proto.c 6.2
SCCS-vsn: sys/kern/uipc_socket.c 6.6
SCCS-vsn: sys/kern/uipc_socket2.c 6.3
SCCS-vsn: sys/kern/uipc_usrreq.c 6.8

usr/src/sys/kern/uipc_domain.c
usr/src/sys/kern/uipc_proto.c
usr/src/sys/kern/uipc_socket.c
usr/src/sys/kern/uipc_socket2.c
usr/src/sys/kern/uipc_usrreq.c

index 6fff983..b562232 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_domain.c   6.1     83/07/29        */
+/*     uipc_domain.c   6.2     84/08/21        */
 
 #include "../h/param.h"
 #include "../h/socket.h"
 
 #include "../h/param.h"
 #include "../h/socket.h"
@@ -32,10 +32,13 @@ domaininit()
 #endif
 #endif
 
 #endif
 #endif
 
-       for (dp = domains; dp; dp = dp->dom_next)
+       for (dp = domains; dp; dp = dp->dom_next) {
+               if (dp->dom_init)
+                       (*dp->dom_init)();
                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
                        if (pr->pr_init)
                                (*pr->pr_init)();
                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
                        if (pr->pr_init)
                                (*pr->pr_init)();
+       }
        pffasttimo();
        pfslowtimo();
 }
        pffasttimo();
        pfslowtimo();
 }
index 6c789cb..73a9929 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_proto.c    6.1     83/07/29        */
+/*     uipc_proto.c    6.2     84/08/21        */
 
 #include "../h/param.h"
 #include "../h/socket.h"
 
 #include "../h/param.h"
 #include "../h/socket.h"
 
 int    uipc_usrreq();
 int    raw_init(),raw_usrreq(),raw_input(),raw_ctlinput();
 
 int    uipc_usrreq();
 int    raw_init(),raw_usrreq(),raw_input(),raw_ctlinput();
+extern struct domain unixdomain;               /* or at least forward */
 
 struct protosw unixsw[] = {
 
 struct protosw unixsw[] = {
-{ SOCK_STREAM, PF_UNIX,        0,              PR_CONNREQUIRED|PR_WANTRCVD,
+{ SOCK_STREAM, &unixdomain,    0,              PR_CONNREQUIRED|PR_WANTRCVD,
   0,           0,              0,              0,
   uipc_usrreq,
   0,           0,              0,              0,
 },
   0,           0,              0,              0,
   uipc_usrreq,
   0,           0,              0,              0,
 },
-{ SOCK_DGRAM,  PF_UNIX,        0,              PR_ATOMIC|PR_ADDR|PR_RIGHTS,
+{ SOCK_DGRAM,  &unixdomain,    0,              PR_ATOMIC|PR_ADDR|PR_RIGHTS,
   0,           0,              0,              0,
   uipc_usrreq,
   0,           0,              0,              0,
   0,           0,              0,              0,
   uipc_usrreq,
   0,           0,              0,              0,
@@ -31,5 +32,8 @@ struct protosw unixsw[] = {
 }
 };
 
 }
 };
 
+int    unp_externalize(), unp_dispose();
+
 struct domain unixdomain =
 struct domain unixdomain =
-    { AF_UNIX, "unix", unixsw, &unixsw[sizeof(unixsw)/sizeof(unixsw[0])] };
+    { AF_UNIX, "unix", 0, unp_externalize, unp_dispose,
+      unixsw, &unixsw[sizeof(unixsw)/sizeof(unixsw[0])] };
index 1ad745c..9a8d447 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_socket.c   6.5     84/08/21        */
+/*     uipc_socket.c   6.6     84/08/21        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -10,6 +10,7 @@
 #include "../h/buf.h"
 #include "../h/mbuf.h"
 #include "../h/un.h"
 #include "../h/buf.h"
 #include "../h/mbuf.h"
 #include "../h/un.h"
+#include "../h/domain.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
@@ -399,8 +400,9 @@ soreceive(so, aname, uio, flags, rightsp)
        struct mbuf **rightsp;
 {
        register struct mbuf *m, *n;
        struct mbuf **rightsp;
 {
        register struct mbuf *m, *n;
-       register int len, error = 0, s, eor, tomark;
+       register int len, error = 0, s, tomark;
        struct protosw *pr = so->so_proto;
        struct protosw *pr = so->so_proto;
+       struct mbuf *nextrecord;
        int moff;
 
        if (rightsp)
        int moff;
 
        if (rightsp)
@@ -457,60 +459,47 @@ restart:
        }
        u.u_ru.ru_msgrcv++;
        m = so->so_rcv.sb_mb;
        }
        u.u_ru.ru_msgrcv++;
        m = so->so_rcv.sb_mb;
-       if (m == 0)
-               panic("receive");
        if (pr->pr_flags & PR_ADDR) {
        if (pr->pr_flags & PR_ADDR) {
-               if ((flags & MSG_PEEK) == 0) {
-                       so->so_rcv.sb_cc -= m->m_len;
-                       so->so_rcv.sb_mbcnt -= MSIZE;
-               }
-               if (aname) {
-                       if (flags & MSG_PEEK) {
+               if (m == 0 || m->m_type != MT_SONAME)
+                       panic("receive 1a");
+               if (flags & MSG_PEEK) {
+                       if (aname)
                                *aname = m_copy(m, 0, m->m_len);
                                *aname = m_copy(m, 0, m->m_len);
-                               if (*aname == NULL)
-                                       panic("receive 2");
-                       } else
-                               *aname = m;
-                       m = m->m_next;
-                       (*aname)->m_next = 0;
-               } else
-                       if (flags & MSG_PEEK)
-                               m = m->m_next;
                        else
                        else
-                               m = m_free(m);
-               if (m == 0)
+                               m = m->m_act;
+               } else {
+                       if (aname) {
+                               *aname = m;
+                               sbfree(&so->so_rcv, m);
+if(m->m_next) panic("receive 1b");
+                               so->so_rcv.sb_mb = m = m->m_act;
+                       } else
+                               m = sbdroprecord(&so->so_rcv);
+               }
+       }
+       if (m && m->m_type == MT_RIGHTS) {
+               if ((pr->pr_flags & PR_RIGHTS) == 0)
                        panic("receive 2a");
                        panic("receive 2a");
-               if (rightsp) {
-                       if (m->m_len)
+               if (flags & MSG_PEEK) {
+                       if (rightsp)
                                *rightsp = m_copy(m, 0, m->m_len);
                                *rightsp = m_copy(m, 0, m->m_len);
-                       else {
-                               *rightsp = m_get(M_DONTWAIT, MT_SONAME);
-                               if (*rightsp)
-                                       (*rightsp)->m_len = 0;
-                       }
-#ifdef notdef
-                       if (*rightsp == NULL)
-                               panic("receive 2b");
-#endif
-               }
-               if (flags & MSG_PEEK)
-                       m = m->m_next;
-               else {
-                       so->so_rcv.sb_cc -= m->m_len;
-                       so->so_rcv.sb_mbcnt -= MSIZE;
-                       m = m_free(m);
+                       else
+                               m = m->m_act;
+               } else {
+                       if (rightsp) {
+                               *rightsp = m;
+                               sbfree(&so->so_rcv, m);
+if(m->m_next) panic("receive 2b");
+                               so->so_rcv.sb_mb = m = m->m_act;
+                       } else
+                               m = sbdroprecord(&so->so_rcv);
                }
                }
-               if (m == 0)
-                       panic("receive 3");
-               if ((flags & MSG_PEEK) == 0)
-                       so->so_rcv.sb_mb = m;
        }
        }
-       eor = 0;
+       if (m == 0)
+               panic("receive 3");
        moff = 0;
        tomark = so->so_oobmark;
        moff = 0;
        tomark = so->so_oobmark;
-       do {
-               if (uio->uio_resid <= 0)
-                       break;
+       while (m && uio->uio_resid > 0 && error == 0) {
                len = uio->uio_resid;
                so->so_state &= ~SS_RCVATMARK;
                if (tomark && len > tomark)
                len = uio->uio_resid;
                so->so_state &= ~SS_RCVATMARK;
                if (tomark && len > tomark)
@@ -522,15 +511,15 @@ restart:
                    uiomove(mtod(m, caddr_t) + moff, (int)len, UIO_READ, uio);
                s = splnet();
                if (len == m->m_len) {
                    uiomove(mtod(m, caddr_t) + moff, (int)len, UIO_READ, uio);
                s = splnet();
                if (len == m->m_len) {
-                       eor = (int)m->m_act;
-                       if (flags & MSG_PEEK)
-                               m = m->m_next;
-                       else {
+                       if ((flags & MSG_PEEK) == 0) {
+                               nextrecord = m->m_act;
                                sbfree(&so->so_rcv, m);
                                MFREE(m, n);
                                sbfree(&so->so_rcv, m);
                                MFREE(m, n);
-                               m = n;
+                               if (m = n)
+                                       m->m_act = nextrecord;
                                so->so_rcv.sb_mb = m;
                                so->so_rcv.sb_mb = m;
-                       }
+                       } else
+                               m = m->m_next;
                        moff = 0;
                } else {
                        if (flags & MSG_PEEK)
                        moff = 0;
                } else {
                        if (flags & MSG_PEEK)
@@ -553,27 +542,20 @@ restart:
                        if (tomark == 0)
                                break;
                }
                        if (tomark == 0)
                                break;
                }
-       } while (m && error == 0 && !eor);
-       if (flags & MSG_PEEK)
-               goto release;
-       if ((so->so_proto->pr_flags & PR_ATOMIC) && eor == 0)
-               do {
-                       if (m == 0)
-                               panic("receive 4");
-                       sbfree(&so->so_rcv, m);
-                       eor = (int)m->m_act;
-                       so->so_rcv.sb_mb = m->m_next;
-                       MFREE(m, n);
-                       m = n;
-               } while (eor == 0);
-       if ((so->so_proto->pr_flags & PR_WANTRCVD) && so->so_pcb)
-               (*so->so_proto->pr_usrreq)(so, PRU_RCVD,
-                   (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0);
+       }
+       if ((flags & MSG_PEEK) == 0) {
+               if (m == 0)
+                       so->so_rcv.sb_mb = nextrecord;
+               else if (pr->pr_flags & PR_ATOMIC)
+                       (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 *)0, (struct mbuf *)0);
+       }
 release:
        sbunlock(&so->so_rcv);
 release:
        sbunlock(&so->so_rcv);
-       if (error == 0 && rightsp &&
-           *rightsp && so->so_proto->pr_family == AF_UNIX)
-               error = unp_externalize(*rightsp);
+       if (error == 0 && rightsp && *rightsp && pr->pr_domain->dom_externalize)
+               error = (*pr->pr_domain->dom_externalize)(*rightsp);
        splx(s);
        return (error);
 }
        splx(s);
        return (error);
 }
@@ -608,8 +590,8 @@ sorflush(so)
        asb = *sb;
        bzero((caddr_t)sb, sizeof (*sb));
        splx(s);
        asb = *sb;
        bzero((caddr_t)sb, sizeof (*sb));
        splx(s);
-       if (pr->pr_family == AF_UNIX && (pr->pr_flags & PR_RIGHTS))
-               unp_scan(asb.sb_mb, unp_discard);
+       if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
+               (*pr->pr_domain->dom_dispose)(asb.sb_mb);
        sbrelease(&asb);
 }
 
        sbrelease(&asb);
 }
 
index b7faa64..a20e727 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_socket2.c  6.2     84/01/11        */
+/*     uipc_socket2.c  6.3     84/08/21        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -285,33 +285,46 @@ sowakeup(so, sb)
  * queue, and other fields allowing select() statements and notification
  * on data availability to be implemented.
  *
  * queue, and other fields allowing select() statements and notification
  * on data availability to be implemented.
  *
+ * Data stored in a socket buffer is maintained as a list of records.
+ * Each record is a list of mbufs chained together with the m_next
+ * field.  Records are chained together with the m_act field. The upper
+ * level routine soreceive() expects the following conventions to be
+ * observed when placing information in the receive buffer:
+ *
+ * 1. If the protocol requires each message be preceded by the sender's
+ *    name, then a record containing that name must be present before
+ *    any associated data (mbuf's must be of type MT_SONAME).
+ * 2. If the protocol supports the exchange of ``access rights'' (really
+ *    just additional data associated with the message), and there are
+ *    ``rights'' to be received, then a record containing this data
+ *    should be present (mbuf's must be of type MT_RIGHTS).
+ * 3. If a name or rights record exists, then it must be followed by
+ *    a data record, perhaps of zero length.
+ *
  * Before using a new socket structure it is first necessary to reserve
  * Before using a new socket structure it is first necessary to reserve
- * buffer space to the socket, by calling sbreserve.  This commits
+ * buffer space to the socket, by calling sbreserve().  This commits
  * some of the available buffer space in the system buffer pool for the
  * some of the available buffer space in the system buffer pool for the
- * socket.  The space should be released by calling sbrelease when the
+ * socket.  The space should be released by calling sbrelease() when the
  * socket is destroyed.
  *
  * socket is destroyed.
  *
- * The routine sbappend() is normally called to append new mbufs
- * to a socket buffer, after checking that adequate space is available
- * comparing the function spspace() with the amount of data to be added.
+ * The routines sbappend() or sbappendrecord() are normally called to
+ * append new mbufs to a socket buffer, after checking that adequate
+ * space is available, comparing the function sbspace() with the amount
+ * of data to be added.  sbappendrecord() differs from sbappend() in
+ * that data supplied is treated as the beginning of a new record.
  * Data is normally removed from a socket buffer in a protocol by
  * first calling m_copy on the socket buffer mbuf chain and sending this
  * to a peer, and then removing the data from the socket buffer with
  * Data is normally removed from a socket buffer in a protocol by
  * first calling m_copy on the socket buffer mbuf chain and sending this
  * to a peer, and then removing the data from the socket buffer with
- * sbdrop when the data is acknowledged by the peer (or immediately
- * in the case of unreliable protocols.)
+ * sbdrop() or sbdroprecord() when the data is acknowledged by the peer
+ * (or immediately in the case of unreliable protocols.)
  *
  *
- * Protocols which do not require connections place both source address
- * and data information in socket buffer queues.  The source addresses
- * are stored in single mbufs after each data item, and are easily found
- * as the data items are all marked with end of record markers.  The
- * sbappendaddr() routine stores a datum and associated address in
- * a socket buffer.  Note that, unlike sbappend(), this routine checks
+ * To place a sender's name, optionally, access rights, and data in a
+ * socket buffer sbappendaddr() should be used.  To place access rights
+ * and data in a socket buffer sbappendrights() should be used.  Note
+ * that unlike sbappend() and sbappendrecord(), these routines check
  * for the caller that there will be enough space to store the data.
  * for the caller that there will be enough space to store the data.
- * It fails if there is not enough space, or if it cannot find
- * a mbuf to store the address in.
- *
- * The higher-level routines sosend and soreceive (in socket.c)
- * also add data to, and remove data from socket buffers repectively.
+ * Each fails if there is not enough space, or if it cannot find mbufs
+ * to store additional information in.
  */
 
 soreserve(so, sndcc, rcvcc)
  */
 
 soreserve(so, sndcc, rcvcc)
@@ -356,104 +369,192 @@ sbrelease(sb)
 }
 
 /*
 }
 
 /*
- * Routines to add (at the end) and remove (from the beginning)
- * data from a mbuf queue.
+ * Routines to add and remove
+ * data from an mbuf queue.
  */
 
 /*
  */
 
 /*
- * Append mbuf queue m to sockbuf sb.
+ * Append mbuf chain m to the last record in the
+ * socket buffer sb.  The additional space associated
+ * the mbuf chain is recorded in sb.  Empty mbufs are
+ * discarded and mbufs are compacted where possible.
  */
 sbappend(sb, m)
  */
 sbappend(sb, m)
-       register struct mbuf *m;
-       register struct sockbuf *sb;
+       struct sockbuf *sb;
+       struct mbuf *m;
 {
        register struct mbuf *n;
 
 {
        register struct mbuf *n;
 
-       n = sb->sb_mb;
-       if (n)
+       if (m == 0)
+               return;
+       if (n = sb->sb_mb) {
+               while (n->m_act)
+                       n = n->m_act;
                while (n->m_next)
                        n = n->m_next;
                while (n->m_next)
                        n = n->m_next;
-       while (m) {
-               if (m->m_len == 0 && (int)m->m_act == 0) {
-                       m = m_free(m);
-                       continue;
-               }
-               if (n && n->m_off <= MMAXOFF && m->m_off <= MMAXOFF &&
-                  (int)n->m_act == 0 && (int)m->m_act == 0 &&
-                  (n->m_off + n->m_len + m->m_len) <= MMAXOFF) {
-                       bcopy(mtod(m, caddr_t), mtod(n, caddr_t) + n->m_len,
-                           (unsigned)m->m_len);
-                       n->m_len += m->m_len;
-                       sb->sb_cc += m->m_len;
-                       m = m_free(m);
-                       continue;
-               }
-               sballoc(sb, m);
-               if (n == 0)
-                       sb->sb_mb = m;
-               else
-                       n->m_next = m;
-               n = m;
-               m = m->m_next;
-               n->m_next = 0;
        }
        }
+       sbcompress(sb, m, n);
 }
 
 /*
 }
 
 /*
- * Append data and address.
- * Return 0 if no space in sockbuf or if
- * can't get mbuf to stuff address in.
+ * As above, except the mbuf chain
+ * begins a new record.
  */
  */
-sbappendaddr(sb, asa, m0, rights0)
-       struct sockbuf *sb;
-       struct sockaddr *asa;
-       struct mbuf *m0, *rights0;
+sbappendrecord(sb, m0)
+       register struct sockbuf *sb;
+       register struct mbuf *m0;
 {
        register struct mbuf *m;
 {
        register struct mbuf *m;
-       register int len = sizeof (struct sockaddr);
-       register struct mbuf *rights;
 
 
-       if (rights0)
-               len += rights0->m_len;
+       if (m0 == 0)
+               return;
+       if (m = sb->sb_mb)
+               while (m->m_act)
+                       m = m->m_act;
+       /*
+        * Put the first mbuf on the queue.
+        * Note this permits zero length records.
+        */
+       sballoc(sb, m0);
+       if (m)
+               m->m_act = m0;
+       else
+               sb->sb_mb = m0;
+       m = m0->m_next;
+       m0->m_next = 0;
+       sbcompress(sb, m, m0);
+}
+
+/*
+ * Append address and data, and optionally, rights
+ * to the receive queue of a socket.  Return 0 if
+ * no space in sockbuf or insufficient mbufs.
+ */
+sbappendaddr(sb, asa, m0, rights0)             /* XXX */
+       register struct sockbuf *sb;
+       struct sockaddr *asa;
+       struct mbuf *rights0, *m0;
+{
+       register struct mbuf *m, *n;
+       int space = sizeof (*asa);
+
        m = m0;
        if (m == 0)
                panic("sbappendaddr");
        m = m0;
        if (m == 0)
                panic("sbappendaddr");
-       for (;;) {
-               len += m->m_len;
-               if (m->m_next == 0) {
-                       m->m_act = (struct mbuf *)1;
-                       break;
-               }
+       do {
+               space += m->m_len;
                m = m->m_next;
                m = m->m_next;
-       }
-       if (len > sbspace(sb))
+       } while (m);
+       if (rights0)
+               space += rights0->m_len;
+       if (space > sbspace(sb))
                return (0);
        m = m_get(M_DONTWAIT, MT_SONAME);
                return (0);
        m = m_get(M_DONTWAIT, MT_SONAME);
-       if (m == NULL)
+       if (m == 0)
                return (0);
                return (0);
-       m->m_len = sizeof (struct sockaddr);
-       m->m_act = (struct mbuf *)1;
        *mtod(m, struct sockaddr *) = *asa;
        *mtod(m, struct sockaddr *) = *asa;
-       if (rights0 == 0 || rights0->m_len == 0) {
-               rights = m_get(M_DONTWAIT, MT_SONAME);
-               if (rights)
-                       rights->m_len = 0;
+       m->m_len = sizeof (*asa);
+       if (rights0) {
+               m->m_act = m_copy(rights0, 0, rights0->m_len);
+               if (m->m_act == 0) {
+                       m_freem(m);
+                       return (0);
+               }
+               sballoc(sb, m);
+               sballoc(sb, m->m_act);
+       } else
+               sballoc(sb, m);
+       if (n = sb->sb_mb) {
+               while (n->m_act)
+                       n = n->m_act;
+               n->m_act = m;
        } else
        } else
-               rights = m_copy(rights0, 0, rights0->m_len);
-       if (rights == 0) {
-               m_freem(m);
+               sb->sb_mb = m;
+       if (m->m_act)
+               m = m->m_act;
+       sballoc(sb, m0);
+       m->m_act = m0;
+       m = m0->m_next;
+       m0->m_next = 0;
+       sbcompress(sb, m, m0);
+       return (1);
+}
+
+#ifdef notdef
+sbappendrights(sb, rights, m0)
+       struct sockbuf *sb;
+       struct mbuf *rights, *m;
+{
+       register struct mbuf *m, *n;
+       int space = 0;
+
+       m = m0;
+       if (m == 0 || rights == 0)
+               panic("sbappendrights");
+       do {
+               space += m->m_len;
+               m = m->m_next;
+       } while (m);
+       space += rights->m_len;
+       if (space > sbspace(sb))
                return (0);
                return (0);
-       }
-       rights->m_act = (struct mbuf *)1;
-       m->m_next = rights;
-       rights->m_next = m0;
-       sbappend(sb, m);
+       m = m_copy(rights, 0, rights->m_len);
+       if (m == 0)
+               return (0);
+       sballoc(sb, m);
+       if (n = sb->sb_mb) {
+               while (n->m_act)
+                       n = n->m_act;
+               n->m_act = m;
+       } else
+               n->m_act = m;
+       sballoc(sb, m0);
+       m->m_act = m0;
+       m = m0->m_next;
+       m0->m_next = 0;
+       sbcompress(sb, m, m0);
        return (1);
 }
        return (1);
 }
+#endif
+
+/*
+ * Compress mbuf chain m into the socket
+ * buffer sb following mbuf n.  If n
+ * is null, the buffer is presumed empty.
+ */
+sbcompress(sb, m, n)
+       register struct sockbuf *sb;
+       register struct mbuf *m, *n;
+{
+
+       while (m) {
+               if (m->m_len == 0) {
+                       m = m_free(m);
+                       continue;
+               }
+               if (n && n->m_off <= MMAXOFF && m->m_off <= MMAXOFF &&
+                   (n->m_off + n->m_len + m->m_len) <= MMAXOFF) {
+                       bcopy(mtod(m, caddr_t), mtod(n, caddr_t) + n->m_len,
+                           (unsigned)m->m_len);
+                       n->m_len += m->m_len;
+                       sb->sb_cc += m->m_len;
+                       m = m_free(m);
+                       continue;
+               }
+               sballoc(sb, m);
+               if (n)
+                       n->m_next = m;
+               else
+                       sb->sb_mb = m;
+               n = m;
+               m = m->m_next;
+               n->m_next = 0;
+       }
+}
 
 /*
 
 /*
- * Free all mbufs on a sockbuf mbuf chain.
- * Check that resource allocations return to 0.
+ * Free all mbufs in a sockbuf.
+ * Check that all resources are reclaimed.
  */
 sbflush(sb)
        register struct sockbuf *sb;
  */
 sbflush(sb)
        register struct sockbuf *sb;
@@ -468,17 +569,25 @@ sbflush(sb)
 }
 
 /*
 }
 
 /*
- * Drop data from (the front of) a sockbuf chain.
+ * Drop data from (the front of) a sockbuf.
  */
  */
+struct mbuf *
 sbdrop(sb, len)
        register struct sockbuf *sb;
        register int len;
 {
 sbdrop(sb, len)
        register struct sockbuf *sb;
        register int len;
 {
-       register struct mbuf *m = sb->sb_mb, *mn;
+       register struct mbuf *m, *mn;
+       struct mbuf *next;
 
 
+       next = (m = sb->sb_mb) ? m->m_act : 0;
        while (len > 0) {
        while (len > 0) {
-               if (m == 0)
-                       panic("sbdrop");
+               if (m == 0) {
+                       if (next == 0)
+                               panic("sbdrop");
+                       m = next;
+                       next = m->m_act;
+                       continue;
+               }
                if (m->m_len > len) {
                        m->m_len -= len;
                        m->m_off += len;
                if (m->m_len > len) {
                        m->m_len -= len;
                        m->m_off += len;
@@ -490,5 +599,31 @@ sbdrop(sb, len)
                MFREE(m, mn);
                m = mn;
        }
                MFREE(m, mn);
                m = mn;
        }
-       sb->sb_mb = m;
+       if (m) {
+               sb->sb_mb = m;
+               m->m_act = next;
+       } else
+               sb->sb_mb = next;
+       return (sb->sb_mb);
+}
+
+/*
+ * Drop a record off the front of a sockbuf
+ * and move the next record to the front.
+ */
+struct mbuf *
+sbdroprecord(sb)
+       register struct sockbuf *sb;
+{
+       register struct mbuf *m, *mn;
+
+       m = sb->sb_mb;
+       if (m) {
+               sb->sb_mb = m->m_act;
+               do {
+                       sbfree(sb, m);
+                       MFREE(m, mn);
+               } while (m = mn);
+       }
+       return (sb->sb_mb);
 }
 }
index 2def6ff..9d4e568 100644 (file)
@@ -1,9 +1,10 @@
-/*     uipc_usrreq.c   6.7     84/08/20        */
+/*     uipc_usrreq.c   6.8     84/08/21        */
 
 #include "../h/param.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/mbuf.h"
 
 #include "../h/param.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/mbuf.h"
+#include "../h/domain.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
@@ -534,6 +535,7 @@ unp_internalize(rights)
 
 int    unp_defer, unp_gcing;
 int    unp_mark();
 
 int    unp_defer, unp_gcing;
 int    unp_mark();
+extern struct domain unixdomain;
 
 unp_gc()
 {
 
 unp_gc()
 {
@@ -564,7 +566,7 @@ restart:
                        if (fp->f_type != DTYPE_SOCKET)
                                continue;
                        so = (struct socket *)fp->f_data;
                        if (fp->f_type != DTYPE_SOCKET)
                                continue;
                        so = (struct socket *)fp->f_data;
-                       if (so->so_proto->pr_family != AF_UNIX ||
+                       if (so->so_proto->pr_domain != &unixdomain ||
                            (so->so_proto->pr_flags&PR_ADDR) == 0)
                                continue;
                        if (so->so_rcv.sb_flags & SB_LOCK) {
                            (so->so_proto->pr_flags&PR_ADDR) == 0)
                                continue;
                        if (so->so_rcv.sb_flags & SB_LOCK) {
@@ -586,34 +588,36 @@ restart:
        unp_gcing = 0;
 }
 
        unp_gcing = 0;
 }
 
-unp_scan(m, op)
-       register struct mbuf *m;
+unp_dispose(m)
+       struct mbuf *m;
+{
+       int unp_discard();
+
+       unp_scan(m, unp_discard);
+}
+
+unp_scan(m0, op)
+       register struct mbuf *m0;
        int (*op)();
 {
        int (*op)();
 {
+       register struct mbuf *m;
        register struct file **rp;
        register int i;
        register struct file **rp;
        register int i;
-       int qfds;
-
-       while (m) {
-               m = m->m_next;
-               if (m == 0)
-                       goto bad;
-               if (m->m_len) {
-                       qfds = m->m_len / sizeof (struct file *);
-                       rp = mtod(m, struct file **);
-                       for (i = 0; i < qfds; i++)
-                               (*op)(*rp++);
-               }
-               do {
-                       m = m->m_next;
-                       if (m == 0)
-                               goto bad;
-               } while (m->m_act == 0);
-               m = m->m_next;
+       int qfds = 0;
+
+       while (m0) {
+               for (m = m0; m; m = m->m_next)
+                       if (m->m_type == MT_RIGHTS && m->m_len) {
+                               qfds = m->m_len / sizeof (struct file *);
+                               rp = mtod(m, struct file **);
+                               for (i = 0; i < qfds; i++)
+                                       (*op)(*rp++);
+                               break;          /* XXX, but saves time */
+                       }
+               m0 = m0->m_next;
        }
        }
-       return;
-bad:
-       panic("unp_gcscan");
+       if (qfds == 0)
+               panic("unp_gcscan");
 }
 
 unp_mark(fp)
 }
 
 unp_mark(fp)