Deleted Added
full compact
uipc_socket.c (177380) uipc_socket.c (177599)
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2004 The FreeBSD Foundation
5 * Copyright (c) 2004-2007 Robert N. M. Watson
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 81 unchanged lines hidden (view full) ---

90 * calls to explicitly manage socket references, soref(), and sorele().
91 * Currently, these are generally required only when transitioning a socket
92 * from a listen queue to a file descriptor, in order to prevent garbage
93 * collection of the socket at an untimely moment. For a number of reasons,
94 * these interfaces are not preferred, and should be avoided.
95 */
96
97#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2004 The FreeBSD Foundation
5 * Copyright (c) 2004-2007 Robert N. M. Watson
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 81 unchanged lines hidden (view full) ---

90 * calls to explicitly manage socket references, soref(), and sorele().
91 * Currently, these are generally required only when transitioning a socket
92 * from a listen queue to a file descriptor, in order to prevent garbage
93 * collection of the socket at an untimely moment. For a number of reasons,
94 * these interfaces are not preferred, and should be avoided.
95 */
96
97#include <sys/cdefs.h>
98__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 177380 2008-03-19 09:58:25Z sobomax $");
98__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 177599 2008-03-25 09:39:02Z ru $");
99
100#include "opt_inet.h"
101#include "opt_mac.h"
102#include "opt_zero.h"
103#include "opt_compat.h"
104
105#include <sys/param.h>
106#include <sys/systm.h>

--- 748 unchanged lines hidden (view full) ---

855 len = cow_send;
856 }
857 if (!cow_send) {
858 m_clget(m, M_WAITOK);
859 len = min(min(MCLBYTES, resid), *space);
860 }
861#else /* ZERO_COPY_SOCKETS */
862 if (top == NULL) {
99
100#include "opt_inet.h"
101#include "opt_mac.h"
102#include "opt_zero.h"
103#include "opt_compat.h"
104
105#include <sys/param.h>
106#include <sys/systm.h>

--- 748 unchanged lines hidden (view full) ---

855 len = cow_send;
856 }
857 if (!cow_send) {
858 m_clget(m, M_WAITOK);
859 len = min(min(MCLBYTES, resid), *space);
860 }
861#else /* ZERO_COPY_SOCKETS */
862 if (top == NULL) {
863 m = m_getcl(M_TRYWAIT, MT_DATA, M_PKTHDR);
863 m = m_getcl(M_WAIT, MT_DATA, M_PKTHDR);
864 m->m_pkthdr.len = 0;
865 m->m_pkthdr.rcvif = NULL;
866 } else
864 m->m_pkthdr.len = 0;
865 m->m_pkthdr.rcvif = NULL;
866 } else
867 m = m_getcl(M_TRYWAIT, MT_DATA, 0);
867 m = m_getcl(M_WAIT, MT_DATA, 0);
868 len = min(min(MCLBYTES, resid), *space);
869#endif /* ZERO_COPY_SOCKETS */
870 } else {
871 if (top == NULL) {
868 len = min(min(MCLBYTES, resid), *space);
869#endif /* ZERO_COPY_SOCKETS */
870 } else {
871 if (top == NULL) {
872 m = m_gethdr(M_TRYWAIT, MT_DATA);
872 m = m_gethdr(M_WAIT, MT_DATA);
873 m->m_pkthdr.len = 0;
874 m->m_pkthdr.rcvif = NULL;
875
876 len = min(min(MHLEN, resid), *space);
877 /*
878 * For datagram protocols, leave room
879 * for protocol headers in first mbuf.
880 */
881 if (atomic && m && len < MHLEN)
882 MH_ALIGN(m, len);
883 } else {
873 m->m_pkthdr.len = 0;
874 m->m_pkthdr.rcvif = NULL;
875
876 len = min(min(MHLEN, resid), *space);
877 /*
878 * For datagram protocols, leave room
879 * for protocol headers in first mbuf.
880 */
881 if (atomic && m && len < MHLEN)
882 MH_ALIGN(m, len);
883 } else {
884 m = m_get(M_TRYWAIT, MT_DATA);
884 m = m_get(M_WAIT, MT_DATA);
885 len = min(min(MLEN, resid), *space);
886 }
887 }
888 if (m == NULL) {
889 error = ENOBUFS;
890 goto out;
891 }
892

--- 406 unchanged lines hidden (view full) ---

1299soreceive_rcvoob(struct socket *so, struct uio *uio, int flags)
1300{
1301 struct protosw *pr = so->so_proto;
1302 struct mbuf *m;
1303 int error;
1304
1305 KASSERT(flags & MSG_OOB, ("soreceive_rcvoob: (flags & MSG_OOB) == 0"));
1306
885 len = min(min(MLEN, resid), *space);
886 }
887 }
888 if (m == NULL) {
889 error = ENOBUFS;
890 goto out;
891 }
892

--- 406 unchanged lines hidden (view full) ---

1299soreceive_rcvoob(struct socket *so, struct uio *uio, int flags)
1300{
1301 struct protosw *pr = so->so_proto;
1302 struct mbuf *m;
1303 int error;
1304
1305 KASSERT(flags & MSG_OOB, ("soreceive_rcvoob: (flags & MSG_OOB) == 0"));
1306
1307 m = m_get(M_TRYWAIT, MT_DATA);
1308 if (m == NULL)
1309 return (ENOBUFS);
1307 m = m_get(M_WAIT, MT_DATA);
1310 error = (*pr->pr_usrreqs->pru_rcvoob)(so, m, flags & MSG_PEEK);
1311 if (error)
1312 goto bad;
1313 do {
1314#ifdef ZERO_COPY_SOCKETS
1315 if (so_zero_copy_receive) {
1316 int disposable;
1317

--- 395 unchanged lines hidden (view full) ---

1713 moff += len;
1714 else {
1715 if (mp != NULL) {
1716 int copy_flag;
1717
1718 if (flags & MSG_DONTWAIT)
1719 copy_flag = M_DONTWAIT;
1720 else
1308 error = (*pr->pr_usrreqs->pru_rcvoob)(so, m, flags & MSG_PEEK);
1309 if (error)
1310 goto bad;
1311 do {
1312#ifdef ZERO_COPY_SOCKETS
1313 if (so_zero_copy_receive) {
1314 int disposable;
1315

--- 395 unchanged lines hidden (view full) ---

1711 moff += len;
1712 else {
1713 if (mp != NULL) {
1714 int copy_flag;
1715
1716 if (flags & MSG_DONTWAIT)
1717 copy_flag = M_DONTWAIT;
1718 else
1721 copy_flag = M_TRYWAIT;
1722 if (copy_flag == M_TRYWAIT)
1719 copy_flag = M_WAIT;
1720 if (copy_flag == M_WAIT)
1723 SOCKBUF_UNLOCK(&so->so_rcv);
1724 *mp = m_copym(m, 0, len, copy_flag);
1721 SOCKBUF_UNLOCK(&so->so_rcv);
1722 *mp = m_copym(m, 0, len, copy_flag);
1725 if (copy_flag == M_TRYWAIT)
1723 if (copy_flag == M_WAIT)
1726 SOCKBUF_LOCK(&so->so_rcv);
1727 if (*mp == NULL) {
1728 /*
1729 * m_copym() couldn't
1730 * allocate an mbuf. Adjust
1731 * uio_resid back (it was
1732 * adjusted down by len
1733 * bytes, which we didn't end

--- 594 unchanged lines hidden (view full) ---

2328
2329/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
2330int
2331soopt_getm(struct sockopt *sopt, struct mbuf **mp)
2332{
2333 struct mbuf *m, *m_prev;
2334 int sopt_size = sopt->sopt_valsize;
2335
1724 SOCKBUF_LOCK(&so->so_rcv);
1725 if (*mp == NULL) {
1726 /*
1727 * m_copym() couldn't
1728 * allocate an mbuf. Adjust
1729 * uio_resid back (it was
1730 * adjusted down by len
1731 * bytes, which we didn't end

--- 594 unchanged lines hidden (view full) ---

2326
2327/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
2328int
2329soopt_getm(struct sockopt *sopt, struct mbuf **mp)
2330{
2331 struct mbuf *m, *m_prev;
2332 int sopt_size = sopt->sopt_valsize;
2333
2336 MGET(m, sopt->sopt_td ? M_TRYWAIT : M_DONTWAIT, MT_DATA);
2334 MGET(m, sopt->sopt_td ? M_WAIT : M_DONTWAIT, MT_DATA);
2337 if (m == NULL)
2338 return ENOBUFS;
2339 if (sopt_size > MLEN) {
2335 if (m == NULL)
2336 return ENOBUFS;
2337 if (sopt_size > MLEN) {
2340 MCLGET(m, sopt->sopt_td ? M_TRYWAIT : M_DONTWAIT);
2338 MCLGET(m, sopt->sopt_td ? M_WAIT : M_DONTWAIT);
2341 if ((m->m_flags & M_EXT) == 0) {
2342 m_free(m);
2343 return ENOBUFS;
2344 }
2345 m->m_len = min(MCLBYTES, sopt_size);
2346 } else {
2347 m->m_len = min(MLEN, sopt_size);
2348 }
2349 sopt_size -= m->m_len;
2350 *mp = m;
2351 m_prev = m;
2352
2353 while (sopt_size) {
2339 if ((m->m_flags & M_EXT) == 0) {
2340 m_free(m);
2341 return ENOBUFS;
2342 }
2343 m->m_len = min(MCLBYTES, sopt_size);
2344 } else {
2345 m->m_len = min(MLEN, sopt_size);
2346 }
2347 sopt_size -= m->m_len;
2348 *mp = m;
2349 m_prev = m;
2350
2351 while (sopt_size) {
2354 MGET(m, sopt->sopt_td ? M_TRYWAIT : M_DONTWAIT, MT_DATA);
2352 MGET(m, sopt->sopt_td ? M_WAIT : M_DONTWAIT, MT_DATA);
2355 if (m == NULL) {
2356 m_freem(*mp);
2357 return ENOBUFS;
2358 }
2359 if (sopt_size > MLEN) {
2353 if (m == NULL) {
2354 m_freem(*mp);
2355 return ENOBUFS;
2356 }
2357 if (sopt_size > MLEN) {
2360 MCLGET(m, sopt->sopt_td != NULL ? M_TRYWAIT :
2358 MCLGET(m, sopt->sopt_td != NULL ? M_WAIT :
2361 M_DONTWAIT);
2362 if ((m->m_flags & M_EXT) == 0) {
2363 m_freem(m);
2364 m_freem(*mp);
2365 return ENOBUFS;
2366 }
2367 m->m_len = min(MCLBYTES, sopt_size);
2368 } else {

--- 589 unchanged lines hidden ---
2359 M_DONTWAIT);
2360 if ((m->m_flags & M_EXT) == 0) {
2361 m_freem(m);
2362 m_freem(*mp);
2363 return ENOBUFS;
2364 }
2365 m->m_len = min(MCLBYTES, sopt_size);
2366 } else {

--- 589 unchanged lines hidden ---