* Try to lock the connected peer of an already locked socket. In some cases * this requires that we unlock the current socket. The pairbusy counter is * used to block concurrent connection attempts while the lock is dropped. The * caller must be careful to revalidate PCB state. */
| 376 | * caller must be careful to revalidate PCB state. |
| 377 | */ |
| 378 | static struct unpcb * |
| 379 | unp_pcb_lock_peer(struct unpcb *unp) |
| 380 | { |
| 381 | struct unpcb *unp2; |
| 382 | |
| 383 | UNP_PCB_LOCK_ASSERT(unp); |
| 384 | unp2 = unp->unp_conn; |
| 385 | if (unp2 == NULL) |
| 386 | return (NULL); |
| 387 | if (__predict_false(unp == unp2)) |
| 388 | return (unp); |
| 389 | |
| 390 | UNP_PCB_UNLOCK_ASSERT(unp2); |
| 391 | |
| 392 | if (__predict_true(UNP_PCB_TRYLOCK(unp2))) |
| 393 | return (unp2); |
| 394 | if ((uintptr_t)unp2 > (uintptr_t)unp) { |
| 395 | UNP_PCB_LOCK(unp2); |
| 396 | return (unp2); |
| 397 | } |
| 398 | unp->unp_pairbusy++; |
| 399 | unp_pcb_hold(unp2); |
| 400 | UNP_PCB_UNLOCK(unp); |
| 401 | |
| 402 | UNP_PCB_LOCK(unp2); |
| 403 | UNP_PCB_LOCK(unp); |
| 404 | KASSERT(unp->unp_conn == unp2 || unp->unp_conn == NULL, |
| 405 | ("%s: socket %p was reconnected", __func__, unp)); |
| 406 | if (--unp->unp_pairbusy == 0 && (unp->unp_flags & UNP_WAITING) != 0) { |
| 407 | unp->unp_flags &= ~UNP_WAITING; |
| 408 | wakeup(unp); |
| 409 | } |
| 410 | if (unp_pcb_rele(unp2)) { |
| 411 | /* unp2 is unlocked. */ |
| 412 | return (NULL); |
| 413 | } |
| 414 | if (unp->unp_conn == NULL) { |
| 415 | UNP_PCB_UNLOCK(unp2); |
| 416 | return (NULL); |
| 417 | } |
| 418 | return (unp2); |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Definitions of protocols supported in the LOCAL domain. |
no test coverage detected