getting reassembly to work
[unix-history] / usr / src / sys / kern / uipc_socket2.c
index 80d403b..dc2ec8c 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_socket2.c  4.12    81/12/02        */
+/*     uipc_socket2.c  4.20    82/01/19        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -53,17 +53,19 @@ soisconnected(so)
        so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING);
        so->so_state |= SS_ISCONNECTED;
        wakeup((caddr_t)&so->so_timeo);
        so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING);
        so->so_state |= SS_ISCONNECTED;
        wakeup((caddr_t)&so->so_timeo);
+       sorwakeup(so);
+       sowwakeup(so);
 }
 
 soisdisconnecting(so)
        struct socket *so;
 {
 
 }
 
 soisdisconnecting(so)
        struct socket *so;
 {
 
-       so->so_state &= ~(SS_ISCONNECTED|SS_ISCONNECTING);
+       so->so_state &= ~SS_ISCONNECTING;
        so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
        wakeup((caddr_t)&so->so_timeo);
        so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
        wakeup((caddr_t)&so->so_timeo);
-       sorwakeup(so);
        sowwakeup(so);
        sowwakeup(so);
+       sorwakeup(so);
 }
 
 soisdisconnected(so)
 }
 
 soisdisconnected(so)
@@ -111,21 +113,31 @@ socantrcvmore(so)
  * Interface routine to select() system
  * call for sockets.
  */
  * Interface routine to select() system
  * call for sockets.
  */
-soselect(so, flag)
+soselect(so, rw)
        register struct socket *so;
        register struct socket *so;
-       int flag;
+       int rw;
 {
 {
+       int s = splnet();
+
+       switch (rw) {
 
 
-       if (flag & FREAD) {
-               if (soreadable(so))
+       case FREAD:
+               if (soreadable(so)) {
+                       splx(s);
                        return (1);
                        return (1);
+               }
                sbselqueue(&so->so_rcv);
                sbselqueue(&so->so_rcv);
-       }
-       if (flag & FWRITE) {
-               if (sowriteable(so))
+               break;
+
+       case FWRITE:
+               if (sowriteable(so)) {
+                       splx(s);
                        return (1);
                        return (1);
+               }
                sbselqueue(&so->so_snd);
                sbselqueue(&so->so_snd);
+               break;
        }
        }
+       splx(s);
        return (0);
 }
 
        return (0);
 }
 
@@ -194,7 +206,7 @@ sbwakeup(sb)
  * 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
  * 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.
+ * 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
  *
  * Protocols which do not require connections place both source address
  * and data information in socket buffer queues.  The source addresses
@@ -207,7 +219,7 @@ sbwakeup(sb)
  * a mbuf to store the address in.
  *
  * The higher-level routines sosend and soreceive (in socket.c)
  * 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.
+ * also add data to, and remove data from socket buffers repectively.
  */
 
 /*
  */
 
 /*
@@ -257,6 +269,10 @@ sbappend(sb, m)
                np = &n->m_next;
        }
        while (m) {
                np = &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) {
                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) {
@@ -302,7 +318,7 @@ sbappendaddr(sb, asa, m0)
        }
        if (len > sbspace(sb))
                return (0);
        }
        if (len > sbspace(sb))
                return (0);
-       m = m_get(0);
+       m = m_get(M_DONTWAIT);
        if (m == 0)
                return (0);
        m->m_off = MMINOFF;
        if (m == 0)
                return (0);
        m->m_off = MMINOFF;
@@ -325,7 +341,8 @@ sbflush(sb)
 
        if (sb->sb_flags & SB_LOCK)
                panic("sbflush");
 
        if (sb->sb_flags & SB_LOCK)
                panic("sbflush");
-       sbdrop(sb, sb->sb_cc);
+       if (sb->sb_cc)
+               sbdrop(sb, 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");
 }
@@ -355,3 +372,18 @@ sbdrop(sb, len)
        }
        sb->sb_mb = m;
 }
        }
        sb->sb_mb = m;
 }
+
+/*
+printm(m)
+       struct mbuf *m;
+{
+
+       printf("<");
+       while (m) {
+               printf("%d,", m->m_len);
+               m = m->m_next;
+       }
+       printf(">");
+       printf("\n");
+}
+*/