* Optimized version of soreceive() for simple datagram cases from userspace. * Unlike in the stream case, we're able to drop a datagram if copyout() * fails, and because we handle datagrams atomically, we don't need to use a * sleep lock to prevent I/O interlacing. */
| 2615 | * sleep lock to prevent I/O interlacing. |
| 2616 | */ |
| 2617 | int |
| 2618 | soreceive_dgram(struct socket *so, struct sockaddr **psa, struct uio *uio, |
| 2619 | struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
| 2620 | { |
| 2621 | struct mbuf *m, *m2; |
| 2622 | int flags, error; |
| 2623 | ssize_t len; |
| 2624 | struct protosw *pr = so->so_proto; |
| 2625 | struct mbuf *nextrecord; |
| 2626 | |
| 2627 | if (psa != NULL) |
| 2628 | *psa = NULL; |
| 2629 | if (controlp != NULL) |
| 2630 | *controlp = NULL; |
| 2631 | if (flagsp != NULL) |
| 2632 | flags = *flagsp &~ MSG_EOR; |
| 2633 | else |
| 2634 | flags = 0; |
| 2635 | |
| 2636 | /* |
| 2637 | * For any complicated cases, fall back to the full |
| 2638 | * soreceive_generic(). |
| 2639 | */ |
| 2640 | if (mp0 != NULL || (flags & MSG_PEEK) || (flags & MSG_OOB)) |
| 2641 | return (soreceive_generic(so, psa, uio, mp0, controlp, |
| 2642 | flagsp)); |
| 2643 | |
| 2644 | /* |
| 2645 | * Enforce restrictions on use. |
| 2646 | */ |
| 2647 | KASSERT((pr->pr_flags & PR_WANTRCVD) == 0, |
| 2648 | ("soreceive_dgram: wantrcvd")); |
| 2649 | KASSERT(pr->pr_flags & PR_ATOMIC, ("soreceive_dgram: !atomic")); |
| 2650 | KASSERT((so->so_rcv.sb_state & SBS_RCVATMARK) == 0, |
| 2651 | ("soreceive_dgram: SBS_RCVATMARK")); |
| 2652 | KASSERT((so->so_proto->pr_flags & PR_CONNREQUIRED) == 0, |
| 2653 | ("soreceive_dgram: P_CONNREQUIRED")); |
| 2654 | |
| 2655 | /* |
| 2656 | * Loop blocking while waiting for a datagram. |
| 2657 | */ |
| 2658 | SOCKBUF_LOCK(&so->so_rcv); |
| 2659 | while ((m = so->so_rcv.sb_mb) == NULL) { |
| 2660 | KASSERT(sbavail(&so->so_rcv) == 0, |
| 2661 | ("soreceive_dgram: sb_mb NULL but sbavail %u", |
| 2662 | sbavail(&so->so_rcv))); |
| 2663 | if (so->so_error) { |
| 2664 | error = so->so_error; |
| 2665 | so->so_error = 0; |
| 2666 | SOCKBUF_UNLOCK(&so->so_rcv); |
| 2667 | return (error); |
| 2668 | } |
| 2669 | if (so->so_rcv.sb_state & SBS_CANTRCVMORE || |
| 2670 | uio->uio_resid == 0) { |
| 2671 | SOCKBUF_UNLOCK(&so->so_rcv); |
| 2672 | return (0); |
| 2673 | } |
| 2674 | if ((so->so_state & SS_NBIO) || |
nothing calls this directly
no test coverage detected