add Berkeley header
[unix-history] / usr / src / sys / kern / uipc_socket2.c
index 11d2319..e4b215a 100644 (file)
@@ -1,9 +1,15 @@
 /*
 /*
- * Copyright (c) 1982 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.
  *
  *
- *     @(#)uipc_socket2.c      6.11 (Berkeley) %G%
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of California at Berkeley. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ *
+ *     @(#)uipc_socket2.c      7.2 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -330,16 +336,16 @@ bad:
 
 /*
  * Allot mbufs to a sockbuf.
 
 /*
  * Allot mbufs to a sockbuf.
+ * Attempt to scale cc so that mbcnt doesn't become limiting
+ * if buffering efficiency is near the normal case.
  */
 sbreserve(sb, cc)
        struct sockbuf *sb;
 {
 
  */
 sbreserve(sb, cc)
        struct sockbuf *sb;
 {
 
-       if ((unsigned) cc > SB_MAX)
+       if ((unsigned) cc > (unsigned)SB_MAX * CLBYTES / (2 * MSIZE + CLBYTES))
                return (0);
                return (0);
-       /* someday maybe this routine will fail... */
        sb->sb_hiwat = cc;
        sb->sb_hiwat = cc;
-       /* * 2 implies names can be no more than 1 mbuf each */
        sb->sb_mbmax = MIN(cc * 2, SB_MAX);
        return (1);
 }
        sb->sb_mbmax = MIN(cc * 2, SB_MAX);
        return (1);
 }
@@ -456,8 +462,7 @@ sbappendaddr(sb, asa, m0, rights0)
                return (0);
        *mtod(m, struct sockaddr *) = *asa;
        m->m_len = sizeof (*asa);
                return (0);
        *mtod(m, struct sockaddr *) = *asa;
        m->m_len = sizeof (*asa);
-       sballoc(sb, m);
-       if (rights0) {
+       if (rights0 && rights0->m_len) {
                m->m_next = m_copy(rights0, 0, rights0->m_len);
                if (m->m_next == 0) {
                        m_freem(m);
                m->m_next = m_copy(rights0, 0, rights0->m_len);
                if (m->m_next == 0) {
                        m_freem(m);
@@ -465,6 +470,7 @@ sbappendaddr(sb, asa, m0, rights0)
                }
                sballoc(sb, m->m_next);
        }
                }
                sballoc(sb, m->m_next);
        }
+       sballoc(sb, m);
        if (n = sb->sb_mb) {
                while (n->m_act)
                        n = n->m_act;
        if (n = sb->sb_mb) {
                while (n->m_act)
                        n = n->m_act;
@@ -553,8 +559,8 @@ sbflush(sb)
 
        if (sb->sb_flags & SB_LOCK)
                panic("sbflush");
 
        if (sb->sb_flags & SB_LOCK)
                panic("sbflush");
-       if (sb->sb_cc)
-               sbdrop(sb, sb->sb_cc);
+       while (sb->sb_mbcnt)
+               sbdrop(sb, (int)sb->sb_cc);
        if (sb->sb_cc || sb->sb_mbcnt || sb->sb_mb)
                panic("sbflush 2");
 }
        if (sb->sb_cc || sb->sb_mbcnt || sb->sb_mb)
                panic("sbflush 2");
 }
@@ -562,7 +568,6 @@ sbflush(sb)
 /*
  * Drop data from (the front of) a sockbuf.
  */
 /*
  * 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;
@@ -600,14 +605,12 @@ sbdrop(sb, len)
                m->m_act = next;
        } else
                sb->sb_mb = next;
                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.
  */
 }
 
 /*
  * 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;
 {
 sbdroprecord(sb)
        register struct sockbuf *sb;
 {
@@ -621,5 +624,4 @@ sbdroprecord(sb)
                        MFREE(m, mn);
                } while (m = mn);
        }
                        MFREE(m, mn);
                } while (m = mn);
        }
-       return (sb->sb_mb);
 }
 }