/*
- * 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"
/*
* 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;
{
- if ((unsigned) cc > SB_MAX)
+ if ((unsigned) cc > (unsigned)SB_MAX * CLBYTES / (2 * MSIZE + CLBYTES))
return (0);
- /* someday maybe this routine will fail... */
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);
}
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);
}
sballoc(sb, m->m_next);
}
+ sballoc(sb, m);
if (n = sb->sb_mb) {
while (n->m_act)
n = n->m_act;
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");
}
/*
* Drop data from (the front of) a sockbuf.
*/
-struct mbuf *
sbdrop(sb, len)
register struct sockbuf *sb;
register int len;
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;
{
MFREE(m, mn);
} while (m = mn);
}
- return (sb->sb_mb);
}