uipc_sockbuf.c (35413) | uipc_sockbuf.c (36079) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93 | 1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93 |
34 * $Id: uipc_socket2.c,v 1.32 1998/04/04 13:25:40 phk Exp $ | 34 * $Id: uipc_socket2.c,v 1.33 1998/04/24 04:15:18 dg Exp $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> | 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> |
39#include <sys/domain.h> |
|
39#include <sys/kernel.h> 40#include <sys/proc.h> 41#include <sys/malloc.h> 42#include <sys/mbuf.h> 43#include <sys/protosw.h> 44#include <sys/stat.h> 45#include <sys/socket.h> 46#include <sys/socketvar.h> --- 150 unchanged lines hidden (view full) --- 197sonewconn(head, connstatus) 198 register struct socket *head; 199 int connstatus; 200{ 201 register struct socket *so; 202 203 if (head->so_qlen > 3 * head->so_qlimit / 2) 204 return ((struct socket *)0); | 40#include <sys/kernel.h> 41#include <sys/proc.h> 42#include <sys/malloc.h> 43#include <sys/mbuf.h> 44#include <sys/protosw.h> 45#include <sys/stat.h> 46#include <sys/socket.h> 47#include <sys/socketvar.h> --- 150 unchanged lines hidden (view full) --- 198sonewconn(head, connstatus) 199 register struct socket *head; 200 int connstatus; 201{ 202 register struct socket *so; 203 204 if (head->so_qlen > 3 * head->so_qlimit / 2) 205 return ((struct socket *)0); |
205 MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_DONTWAIT); | 206 so = soalloc(0); |
206 if (so == NULL) 207 return ((struct socket *)0); | 207 if (so == NULL) 208 return ((struct socket *)0); |
208 bzero((caddr_t)so, sizeof(*so)); | |
209 so->so_head = head; 210 so->so_type = head->so_type; 211 so->so_options = head->so_options &~ SO_ACCEPTCONN; 212 so->so_linger = head->so_linger; 213 so->so_state = head->so_state | SS_NOFDREF; 214 so->so_proto = head->so_proto; 215 so->so_timeo = head->so_timeo; 216 so->so_pgid = head->so_pgid; 217 so->so_uid = head->so_uid; 218 (void) soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat); 219 220 if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) { | 209 so->so_head = head; 210 so->so_type = head->so_type; 211 so->so_options = head->so_options &~ SO_ACCEPTCONN; 212 so->so_linger = head->so_linger; 213 so->so_state = head->so_state | SS_NOFDREF; 214 so->so_proto = head->so_proto; 215 so->so_timeo = head->so_timeo; 216 so->so_pgid = head->so_pgid; 217 so->so_uid = head->so_uid; 218 (void) soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat); 219 220 if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) { |
221 (void) free((caddr_t)so, M_SOCKET); | 221 sodealloc(so); |
222 return ((struct socket *)0); 223 } 224 225 if (connstatus) { 226 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list); 227 so->so_state |= SS_COMP; 228 } else { 229 TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list); --- 655 unchanged lines hidden (view full) --- 885 MALLOC(sa2, struct sockaddr *, sa->sa_len, M_SONAME, 886 canwait ? M_WAITOK : M_NOWAIT); 887 if (sa2) 888 bcopy(sa, sa2, sa->sa_len); 889 return sa2; 890} 891 892/* | 222 return ((struct socket *)0); 223 } 224 225 if (connstatus) { 226 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list); 227 so->so_state |= SS_COMP; 228 } else { 229 TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list); --- 655 unchanged lines hidden (view full) --- 885 MALLOC(sa2, struct sockaddr *, sa->sa_len, M_SONAME, 886 canwait ? M_WAITOK : M_NOWAIT); 887 if (sa2) 888 bcopy(sa, sa2, sa->sa_len); 889 return sa2; 890} 891 892/* |
893 * Create an external-format (``xsocket'') structure using the information 894 * in the kernel-format socket structure pointed to by so. This is done 895 * to reduce the spew of irrelevant information over this interface, 896 * to isolate user code from changes in the kernel structure, and 897 * potentially to provide information-hiding if we decide that 898 * some of this information should be hidden from users. 899 */ 900void 901sotoxsocket(struct socket *so, struct xsocket *xso) 902{ 903 xso->xso_len = sizeof *xso; 904 xso->xso_so = so; 905 xso->so_type = so->so_type; 906 xso->so_options = so->so_options; 907 xso->so_linger = so->so_linger; 908 xso->so_state = so->so_state; 909 xso->so_pcb = so->so_pcb; 910 xso->xso_protocol = so->so_proto->pr_protocol; 911 xso->xso_family = so->so_proto->pr_domain->dom_family; 912 xso->so_qlen = so->so_qlen; 913 xso->so_incqlen = so->so_incqlen; 914 xso->so_qlimit = so->so_qlimit; 915 xso->so_timeo = so->so_timeo; 916 xso->so_error = so->so_error; 917 xso->so_pgid = so->so_pgid; 918 xso->so_oobmark = so->so_oobmark; 919 sbtoxsockbuf(&so->so_snd, &xso->so_snd); 920 sbtoxsockbuf(&so->so_rcv, &xso->so_rcv); 921 xso->so_uid = so->so_uid; 922} 923 924/* 925 * This does the same for sockbufs. Note that the xsockbuf structure, 926 * since it is always embedded in a socket, does not include a self 927 * pointer nor a length. We make this entry point public in case 928 * some other mechanism needs it. 929 */ 930void 931sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb) 932{ 933 xsb->sb_cc = sb->sb_cc; 934 xsb->sb_hiwat = sb->sb_hiwat; 935 xsb->sb_mbcnt = sb->sb_mbcnt; 936 xsb->sb_mbmax = sb->sb_mbmax; 937 xsb->sb_lowat = sb->sb_lowat; 938 xsb->sb_flags = sb->sb_flags; 939 xsb->sb_timeo = sb->sb_timeo; 940} 941 942/* |
|
893 * Here is the definition of some of the basic objects in the kern.ipc 894 * branch of the MIB. 895 */ 896SYSCTL_NODE(_kern, KERN_IPC, ipc, CTLFLAG_RW, 0, "IPC"); 897 898/* This takes the place of kern.maxsockbuf, which moved to kern.ipc. */ 899static int dummy; 900SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW, &dummy, 0, ""); 901 902SYSCTL_INT(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLFLAG_RW, &sb_max, 0, ""); | 943 * Here is the definition of some of the basic objects in the kern.ipc 944 * branch of the MIB. 945 */ 946SYSCTL_NODE(_kern, KERN_IPC, ipc, CTLFLAG_RW, 0, "IPC"); 947 948/* This takes the place of kern.maxsockbuf, which moved to kern.ipc. */ 949static int dummy; 950SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW, &dummy, 0, ""); 951 952SYSCTL_INT(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLFLAG_RW, &sb_max, 0, ""); |
953SYSCTL_INT(_kern_ipc, OID_AUTO, maxsockets, CTLFLAG_RD, &maxsockets, 0, ""); |
|
903SYSCTL_INT(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW, 904 &sb_efficiency, 0, ""); 905SYSCTL_INT(_kern_ipc, KIPC_NMBCLUSTERS, nmbclusters, CTLFLAG_RD, &nmbclusters, 0, ""); 906 | 954SYSCTL_INT(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW, 955 &sb_efficiency, 0, ""); 956SYSCTL_INT(_kern_ipc, KIPC_NMBCLUSTERS, nmbclusters, CTLFLAG_RD, &nmbclusters, 0, ""); 957 |