]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/uipc_socket2.c
xnu-792.6.61.tar.gz
[apple/xnu.git] / bsd / kern / uipc_socket2.c
index 1d324fc8b55a86b19b2da1d42f4754b992c5649e..30750607ff19d67fc046f0e5df052b17bde6bf15 100644 (file)
@@ -142,18 +142,22 @@ soisconnected(so)
        sflt_notify(so, sock_evt_connected, NULL);
        
        if (head && (so->so_state & SS_INCOMP)) {
-               if (head->so_proto->pr_getlock != NULL) 
+               so->so_state &= ~SS_INCOMP;
+               so->so_state |= SS_COMP;
+               if (head->so_proto->pr_getlock != NULL) {
+                       socket_unlock(so, 0);
                        socket_lock(head, 1);
+               }
                postevent(head, 0, EV_RCONN);
                TAILQ_REMOVE(&head->so_incomp, so, so_list);
                head->so_incqlen--;
-               so->so_state &= ~SS_INCOMP;
                TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
-               so->so_state |= SS_COMP;
                sorwakeup(head);
                wakeup_one((caddr_t)&head->so_timeo);
-               if (head->so_proto->pr_getlock != NULL) 
+               if (head->so_proto->pr_getlock != NULL) {
                        socket_unlock(head, 1);
+                       socket_lock(so, 0);
+               }
        } else {
                postevent(so, 0, EV_WCONN);
                wakeup((caddr_t)&so->so_timeo);
@@ -291,16 +295,19 @@ sonewconn_internal(head, connstatus)
        }
 
        /*
-        * Must be done with head unlocked to avoid deadlock with pcb list
+        * Must be done with head unlocked to avoid deadlock for protocol with per socket mutexes.
         */
-       socket_unlock(head, 0);
+       if (head->so_proto->pr_unlock)
+               socket_unlock(head, 0);
        if (((*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL) != 0) || error) {
                sflt_termsock(so);
                sodealloc(so);
-               socket_lock(head, 0);
+               if (head->so_proto->pr_unlock)
+                       socket_lock(head, 0);
                return ((struct socket *)0);
        }
-       socket_lock(head, 0);
+       if (head->so_proto->pr_unlock)
+               socket_lock(head, 0);
 #ifdef __APPLE__
        so->so_proto->pr_domain->dom_refs++;
 #endif