Use the pool allocator for sockets.

This commit is contained in:
thorpej 1998-08-02 04:53:11 +00:00
parent 5a33f6d7e8
commit a4c7bab10e
4 changed files with 28 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_main.c,v 1.127 1998/08/01 01:36:35 thorpej Exp $ */
/* $NetBSD: init_main.c,v 1.128 1998/08/02 04:53:12 thorpej Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou. All rights reserved.
@ -67,6 +67,7 @@
#include <sys/clist.h>
#endif
#include <sys/device.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <sys/reboot.h>
#include <sys/user.h>
@ -208,6 +209,9 @@ main()
*/
mbinit();
/* Initialize sockets. */
soinit();
disk_init(); /* must come before autoconfiguration */
tty_init(); /* initialise tty list */
#if NRND > 0

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_socket.c,v 1.36 1998/07/31 22:50:52 perry Exp $ */
/* $NetBSD: uipc_socket.c,v 1.37 1998/08/02 04:53:12 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
@ -50,6 +50,17 @@
#include <sys/socketvar.h>
#include <sys/signalvar.h>
#include <sys/resourcevar.h>
#include <sys/pool.h>
struct pool socket_pool;
void
soinit()
{
pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0,
"sockpl", 0, NULL, NULL, M_SOCKET);
}
/*
* Socket operation routines.
@ -79,7 +90,7 @@ socreate(dom, aso, type, proto)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT);
so = pool_get(&socket_pool, PR_WAITOK);
bzero((caddr_t)so, sizeof(*so));
TAILQ_INIT(&so->so_q0);
TAILQ_INIT(&so->so_q);
@ -156,7 +167,7 @@ sofree(so)
}
sbrelease(&so->so_snd);
sorflush(so);
FREE(so, M_SOCKET);
pool_put(&socket_pool, so);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_socket2.c,v 1.24 1998/04/25 17:35:18 matt Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.25 1998/08/02 04:53:12 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
@ -161,9 +161,9 @@ sonewconn1(head, connstatus)
if (head->so_qlen + head->so_q0len > 3 * head->so_qlimit / 2)
return ((struct socket *)0);
MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_DONTWAIT);
so = pool_get(&socket_pool, PR_NOWAIT);
if (so == NULL)
return ((struct socket *)0);
return (NULL);
bzero((caddr_t)so, sizeof(*so));
so->so_type = head->so_type;
so->so_options = head->so_options &~ SO_ACCEPTCONN;
@ -180,8 +180,8 @@ sonewconn1(head, connstatus)
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0,
(struct proc *)0)) {
(void) soqremque(so, soqueue);
(void) free((caddr_t)so, M_SOCKET);
return ((struct socket *)0);
pool_put(&socket_pool, so);
return (NULL);
}
if (connstatus) {
sorwakeup(head);

View File

@ -1,4 +1,4 @@
/* $NetBSD: socketvar.h,v 1.30 1998/06/30 05:33:11 thorpej Exp $ */
/* $NetBSD: socketvar.h,v 1.31 1998/08/02 04:53:11 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1986, 1990, 1993
@ -224,6 +224,8 @@ struct socket *sonewconn1 __P((struct socket *head, int connstatus));
/* strings for sleep message: */
extern const char netio[], netcon[], netcls[];
extern struct pool socket_pool;
struct mbuf;
struct sockaddr;
struct proc;
@ -263,6 +265,7 @@ void sbrelease __P((struct sockbuf *sb));
int sbreserve __P((struct sockbuf *sb, u_long cc));
int sbwait __P((struct sockbuf *sb));
int sb_lock __P((struct sockbuf *sb));
void soinit __P((void));
int soabort __P((struct socket *so));
int soaccept __P((struct socket *so, struct mbuf *nam));
int sobind __P((struct socket *so, struct mbuf *nam));