BSD 4_4 release
[unix-history] / usr / src / sys / kern / uipc_socket2.c
index af76238..d4af592 100644 (file)
@@ -1,36 +1,48 @@
 /*
 /*
- * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  Neither the name of the University nor the names of
- * its contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)uipc_socket2.c      7.15 (Berkeley) 6/28/90
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)uipc_socket2.c      8.1 (Berkeley) 6/10/93
  */
 
  */
 
-#include "param.h"
-#include "systm.h"
-#include "user.h"
-#include "proc.h"
-#include "file.h"
-#include "buf.h"
-#include "malloc.h"
-#include "mbuf.h"
-#include "protosw.h"
-#include "socket.h"
-#include "socketvar.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/file.h>
+#include <sys/buf.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
 
 /*
  * Primitive routines for operating on sockets and socket buffers
 
 /*
  * Primitive routines for operating on sockets and socket buffers
@@ -244,26 +256,6 @@ socantrcvmore(so)
        sorwakeup(so);
 }
 
        sorwakeup(so);
 }
 
-/*
- * Socket select/wakeup routines.
- */
-
-/*
- * Queue a process for a select on a socket buffer.
- */
-sbselqueue(sb)
-       struct sockbuf *sb;
-{
-       struct proc *p;
-
-       if ((p = sb->sb_sel) && p->p_wchan == (caddr_t)&selwait)
-               sb->sb_flags |= SB_COLL;
-       else {
-               sb->sb_sel = u.u_procp;
-               sb->sb_flags |= SB_SEL;
-       }
-}
-
 /*
  * Wait for data to arrive at/drain from a socket buffer.
  */
 /*
  * Wait for data to arrive at/drain from a socket buffer.
  */
@@ -308,11 +300,8 @@ sowakeup(so, sb)
 {
        struct proc *p;
 
 {
        struct proc *p;
 
-       if (sb->sb_sel) {
-               selwakeup(sb->sb_sel, sb->sb_flags & SB_COLL);
-               sb->sb_sel = 0;
-               sb->sb_flags &= ~(SB_SEL|SB_COLL);
-       }
+       selwakeup(&sb->sb_sel);
+       sb->sb_flags &= ~SB_SEL;
        if (sb->sb_flags & SB_WAIT) {
                sb->sb_flags &= ~SB_WAIT;
                wakeup((caddr_t)&sb->sb_cc);
        if (sb->sb_flags & SB_WAIT) {
                sb->sb_flags &= ~SB_WAIT;
                wakeup((caddr_t)&sb->sb_cc);
@@ -451,12 +440,12 @@ sbappend(sb, m)
        if (n = sb->sb_mb) {
                while (n->m_nextpkt)
                        n = n->m_nextpkt;
        if (n = sb->sb_mb) {
                while (n->m_nextpkt)
                        n = n->m_nextpkt;
-               while (n->m_next)
+               do {
                        if (n->m_flags & M_EOR) {
                                sbappendrecord(sb, m); /* XXXXXX!!!! */
                                return;
                        if (n->m_flags & M_EOR) {
                                sbappendrecord(sb, m); /* XXXXXX!!!! */
                                return;
-                       } else
-                               n = n->m_next;
+                       }
+               } while (n->m_next && (n = n->m_next));
        }
        sbcompress(sb, m, n);
 }
        }
        sbcompress(sb, m, n);
 }
@@ -649,10 +638,14 @@ sbcompress(sb, m, n)
        register struct mbuf *m, *n;
 {
        register int eor = 0;
        register struct mbuf *m, *n;
 {
        register int eor = 0;
+       register struct mbuf *o;
 
        while (m) {
                eor |= m->m_flags & M_EOR;
 
        while (m) {
                eor |= m->m_flags & M_EOR;
-               if (m->m_len == 0) {
+               if (m->m_len == 0 &&
+                   (eor == 0 ||
+                    (((o = m->m_next) || (o = n)) &&
+                     o->m_type == m->m_type))) {
                        m = m_free(m);
                        continue;
                }
                        m = m_free(m);
                        continue;
                }
@@ -676,8 +669,12 @@ sbcompress(sb, m, n)
                m = m->m_next;
                n->m_next = 0;
        }
                m = m->m_next;
                n->m_next = 0;
        }
-       if (n)
-               n->m_flags |= eor;
+       if (eor) {
+               if (n)
+                       n->m_flags |= eor;
+               else
+                       printf("semi-panic: sbcompress\n");
+       }
 }
 
 /*
 }
 
 /*