Modify soalloc() API so that it accepts a malloc flags argument rather

than a "waitok" argument.  Callers now passing M_WAITOK or M_NOWAIT
rather than 0 or 1.  This simplifies the soalloc() logic, and also
makes the waiting behavior of soalloc() more clear in the calling
context.

Submitted by:	sam
This commit is contained in:
Robert Watson 2004-02-29 17:54:05 +00:00
parent 2cf6bdac50
commit 2bc87dcfbe
4 changed files with 6 additions and 13 deletions

@ -189,7 +189,7 @@ sonewconn(head, connstatus)
if (head->so_qlen > 3 * head->so_qlimit / 2) if (head->so_qlen > 3 * head->so_qlimit / 2)
return ((struct socket *)0); return ((struct socket *)0);
so = soalloc(0); so = soalloc(M_NOWAIT);
if (so == NULL) if (so == NULL)
return ((struct socket *)0); return ((struct socket *)0);
if ((head->so_options & SO_ACCEPTFILTER) != 0) if ((head->so_options & SO_ACCEPTFILTER) != 0)

@ -128,21 +128,14 @@ SYSCTL_INT(_kern_ipc_zero_copy, OID_AUTO, send, CTLFLAG_RW,
* soalloc() returns a socket with a ref count of 0. * soalloc() returns a socket with a ref count of 0.
*/ */
struct socket * struct socket *
soalloc(waitok) soalloc(int mflags)
int waitok;
{ {
struct socket *so; struct socket *so;
#ifdef MAC #ifdef MAC
int error; int error;
#endif #endif
int flag;
if (waitok == 1) so = uma_zalloc(socket_zone, mflags | M_ZERO);
flag = M_WAITOK;
else
flag = M_NOWAIT;
flag |= M_ZERO;
so = uma_zalloc(socket_zone, flag);
if (so) { if (so) {
#ifdef MAC #ifdef MAC
error = mac_init_socket(so, flag); error = mac_init_socket(so, flag);
@ -195,7 +188,7 @@ socreate(dom, aso, type, proto, cred, td)
if (prp->pr_type != type) if (prp->pr_type != type)
return (EPROTOTYPE); return (EPROTOTYPE);
so = soalloc(1); so = soalloc(M_WAITOK);
if (so == NULL) if (so == NULL)
return (ENOBUFS); return (ENOBUFS);

@ -189,7 +189,7 @@ sonewconn(head, connstatus)
if (head->so_qlen > 3 * head->so_qlimit / 2) if (head->so_qlen > 3 * head->so_qlimit / 2)
return ((struct socket *)0); return ((struct socket *)0);
so = soalloc(0); so = soalloc(M_NOWAIT);
if (so == NULL) if (so == NULL)
return ((struct socket *)0); return ((struct socket *)0);
if ((head->so_options & SO_ACCEPTFILTER) != 0) if ((head->so_options & SO_ACCEPTFILTER) != 0)

@ -378,8 +378,8 @@ int sbwait(struct sockbuf *sb);
int sb_lock(struct sockbuf *sb); int sb_lock(struct sockbuf *sb);
int soabort(struct socket *so); int soabort(struct socket *so);
int soaccept(struct socket *so, struct sockaddr **nam); int soaccept(struct socket *so, struct sockaddr **nam);
struct socket *soalloc(int mflags);
int socheckuid(struct socket *so, uid_t uid); int socheckuid(struct socket *so, uid_t uid);
struct socket *soalloc(int waitok);
int sobind(struct socket *so, struct sockaddr *nam, struct thread *td); int sobind(struct socket *so, struct sockaddr *nam, struct thread *td);
void socantrcvmore(struct socket *so); void socantrcvmore(struct socket *so);
void socantsendmore(struct socket *so); void socantsendmore(struct socket *so);