* Socket buffer (struct sockbuf) utility routines. * * Each socket contains two socket buffers: one for sending data and one for * receiving data. Each buffer contains a queue of mbufs, information about * the number of mbufs and amount of data in the queue, and other fields * allowing select() statements and notification on data availability to be * implemented. * * Data stored in a sock
| 559 | * be released by calling sbrelease() when the socket is destroyed. |
| 560 | */ |
| 561 | int |
| 562 | soreserve(struct socket *so, u_long sndcc, u_long rcvcc) |
| 563 | { |
| 564 | struct thread *td = curthread; |
| 565 | |
| 566 | SOCKBUF_LOCK(&so->so_snd); |
| 567 | SOCKBUF_LOCK(&so->so_rcv); |
| 568 | if (sbreserve_locked(&so->so_snd, sndcc, so, td) == 0) |
| 569 | goto bad; |
| 570 | if (sbreserve_locked(&so->so_rcv, rcvcc, so, td) == 0) |
| 571 | goto bad2; |
| 572 | if (so->so_rcv.sb_lowat == 0) |
| 573 | so->so_rcv.sb_lowat = 1; |
| 574 | if (so->so_snd.sb_lowat == 0) |
| 575 | so->so_snd.sb_lowat = MCLBYTES; |
| 576 | if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat) |
| 577 | so->so_snd.sb_lowat = so->so_snd.sb_hiwat; |
| 578 | SOCKBUF_UNLOCK(&so->so_rcv); |
| 579 | SOCKBUF_UNLOCK(&so->so_snd); |
| 580 | return (0); |
| 581 | bad2: |
| 582 | sbrelease_locked(&so->so_snd, so); |
| 583 | bad: |
| 584 | SOCKBUF_UNLOCK(&so->so_rcv); |
| 585 | SOCKBUF_UNLOCK(&so->so_snd); |
| 586 | return (ENOBUFS); |
| 587 | } |
| 588 | |
| 589 | static int |
| 590 | sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS) |
no test coverage detected