BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / kern / uipc_socket.c
index d4dfb6f..38a32b1 100644 (file)
@@ -2,13 +2,38 @@
  * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * 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_socket.c       7.26 (Berkeley) %G%
+ * 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_socket.c       7.28 (Berkeley) 5/4/91
  */
 
 #include "param.h"
  */
 
 #include "param.h"
-#include "user.h"
 #include "proc.h"
 #include "file.h"
 #include "malloc.h"
 #include "proc.h"
 #include "file.h"
 #include "malloc.h"
@@ -18,7 +43,7 @@
 #include "protosw.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "protosw.h"
 #include "socket.h"
 #include "socketvar.h"
-#include "time.h"
+#include "resourcevar.h"
 
 /*
  * Socket operation routines.
 
 /*
  * Socket operation routines.
  * sys_socket.c or from a system process, and
  * implement the semantics of socket operations by
  * switching out to the protocol specific routines.
  * sys_socket.c or from a system process, and
  * implement the semantics of socket operations by
  * switching out to the protocol specific routines.
- *
- * TODO:
- *     test socketpair
- *     clean up async
- *     out-of-band is a kludge
  */
 /*ARGSUSED*/
 socreate(dom, aso, type, proto)
  */
 /*ARGSUSED*/
 socreate(dom, aso, type, proto)
@@ -38,6 +58,7 @@ socreate(dom, aso, type, proto)
        register int type;
        int proto;
 {
        register int type;
        int proto;
 {
+       struct proc *p = curproc;               /* XXX */
        register struct protosw *prp;
        register struct socket *so;
        register int error;
        register struct protosw *prp;
        register struct socket *so;
        register int error;
@@ -53,7 +74,7 @@ socreate(dom, aso, type, proto)
        MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT);
        bzero((caddr_t)so, sizeof(*so));
        so->so_type = type;
        MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT);
        bzero((caddr_t)so, sizeof(*so));
        so->so_type = type;
-       if (u.u_uid == 0)
+       if (p->p_ucred->cr_uid == 0)
                so->so_state = SS_PRIV;
        so->so_proto = prp;
        error =
                so->so_state = SS_PRIV;
        so->so_proto = prp;
        error =
@@ -286,6 +307,7 @@ sosend(so, addr, uio, top, control, flags)
        struct mbuf *control;
        int flags;
 {
        struct mbuf *control;
        int flags;
 {
+       struct proc *p = curproc;               /* XXX */
        struct mbuf **mp;
        register struct mbuf *m;
        register long space, len, resid;
        struct mbuf **mp;
        register struct mbuf *m;
        register long space, len, resid;
@@ -299,7 +321,7 @@ sosend(so, addr, uio, top, control, flags)
        dontroute =
            (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
            (so->so_proto->pr_flags & PR_ATOMIC);
        dontroute =
            (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
            (so->so_proto->pr_flags & PR_ATOMIC);
-       u.u_ru.ru_msgsnd++;
+       p->p_stats->p_ru.ru_msgsnd++;
        if (control)
                clen = control->m_len;
 #define        snderr(errno)   { error = errno; splx(s); goto release; }
        if (control)
                clen = control->m_len;
 #define        snderr(errno)   { error = errno; splx(s); goto release; }
@@ -315,7 +337,8 @@ restart:
                        snderr(so->so_error);
                if ((so->so_state & SS_ISCONNECTED) == 0) {
                        if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
                        snderr(so->so_error);
                if ((so->so_state & SS_ISCONNECTED) == 0) {
                        if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
-                               if ((so->so_state & SS_ISCONFIRMING) == 0)
+                               if ((so->so_state & SS_ISCONFIRMING) == 0 &&
+                                   !(resid == 0 && clen != 0))
                                        snderr(ENOTCONN);
                        } else if (addr == 0)
                                snderr(EDESTADDRREQ);
                                        snderr(ENOTCONN);
                        } else if (addr == 0)
                                snderr(EDESTADDRREQ);
@@ -450,6 +473,7 @@ soreceive(so, paddr, uio, mp0, controlp, flagsp)
        struct mbuf **controlp;
        int *flagsp;
 {
        struct mbuf **controlp;
        int *flagsp;
 {
+       struct proc *p = curproc;               /* XXX */
        register struct mbuf *m, **mp;
        register int flags, len, error, s, offset;
        struct protosw *pr = so->so_proto;
        register struct mbuf *m, **mp;
        register int flags, len, error, s, offset;
        struct protosw *pr = so->so_proto;
@@ -549,7 +573,7 @@ restart:
                goto restart;
        }
 dontblock:
                goto restart;
        }
 dontblock:
-       u.u_ru.ru_msgrcv++;
+       p->p_stats->p_ru.ru_msgrcv++;
        nextrecord = m->m_nextpkt;
        if (pr->pr_flags & PR_ADDR) {
 #ifdef DIAGNOSTIC
        nextrecord = m->m_nextpkt;
        if (pr->pr_flags & PR_ADDR) {
 #ifdef DIAGNOSTIC