uipc_socket.c (130801) | uipc_socket.c (130831) |
---|---|
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 --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 30 */ 31 32#include <sys/cdefs.h> | 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 --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 130801 2004-06-20 17:50:42Z rwatson $"); | 33__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 130831 2004-06-21 00:20:43Z rwatson $"); |
34 35#include "opt_inet.h" 36#include "opt_mac.h" 37#include "opt_zero.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/fcntl.h> --- 301 unchanged lines hidden (view full) --- 343 KASSERT((so->so_qstate & SQ_COMP) == 0 && 344 (so->so_qstate & SQ_INCOMP) == 0, 345 ("sofree: so_head == NULL, but still SQ_COMP(%d) or SQ_INCOMP(%d)", 346 so->so_qstate & SQ_COMP, so->so_qstate & SQ_INCOMP)); 347 ACCEPT_UNLOCK(); 348 SOCKBUF_LOCK(&so->so_snd); 349 so->so_snd.sb_flags |= SB_NOINTR; 350 (void)sblock(&so->so_snd, M_WAITOK); | 34 35#include "opt_inet.h" 36#include "opt_mac.h" 37#include "opt_zero.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/fcntl.h> --- 301 unchanged lines hidden (view full) --- 343 KASSERT((so->so_qstate & SQ_COMP) == 0 && 344 (so->so_qstate & SQ_INCOMP) == 0, 345 ("sofree: so_head == NULL, but still SQ_COMP(%d) or SQ_INCOMP(%d)", 346 so->so_qstate & SQ_COMP, so->so_qstate & SQ_INCOMP)); 347 ACCEPT_UNLOCK(); 348 SOCKBUF_LOCK(&so->so_snd); 349 so->so_snd.sb_flags |= SB_NOINTR; 350 (void)sblock(&so->so_snd, M_WAITOK); |
351 socantsendmore(so); | 351 /* 352 * socantsendmore_locked() drops the socket buffer mutex so that it 353 * can safely perform wakeups. Re-acquire the mutex before 354 * continuing. 355 */ 356 socantsendmore_locked(so); 357 SOCKBUF_LOCK(&so->so_snd); |
352 sbunlock(&so->so_snd); | 358 sbunlock(&so->so_snd); |
353 sbrelease(&so->so_snd, so); | 359 sbrelease_locked(&so->so_snd, so); |
354 SOCKBUF_UNLOCK(&so->so_snd); 355 sorflush(so); 356 sodealloc(so); 357} 358 359/* 360 * Close a socket on last file table reference removal. 361 * Initiate disconnect if connected. --- 835 unchanged lines hidden (view full) --- 1197 nextrecord = m->m_nextpkt; 1198 } 1199 } 1200 1201 if (m != NULL && pr->pr_flags & PR_ATOMIC) { 1202 flags |= MSG_TRUNC; 1203 if ((flags & MSG_PEEK) == 0) { 1204 SOCKBUF_LOCK_ASSERT(&so->so_rcv); | 360 SOCKBUF_UNLOCK(&so->so_snd); 361 sorflush(so); 362 sodealloc(so); 363} 364 365/* 366 * Close a socket on last file table reference removal. 367 * Initiate disconnect if connected. --- 835 unchanged lines hidden (view full) --- 1203 nextrecord = m->m_nextpkt; 1204 } 1205 } 1206 1207 if (m != NULL && pr->pr_flags & PR_ATOMIC) { 1208 flags |= MSG_TRUNC; 1209 if ((flags & MSG_PEEK) == 0) { 1210 SOCKBUF_LOCK_ASSERT(&so->so_rcv); |
1205 (void) sbdroprecord(&so->so_rcv); | 1211 (void) sbdroprecord_locked(&so->so_rcv); |
1206 } 1207 } 1208 if ((flags & MSG_PEEK) == 0) { 1209 if (m == NULL) { 1210 /* 1211 * First part is an inline SB_EMPTY_FIXUP(). Second 1212 * part makes sure sb_lastrecord is up-to-date if 1213 * there is still data in the socket buffer. --- 52 unchanged lines hidden (view full) --- 1266void 1267sorflush(so) 1268 struct socket *so; 1269{ 1270 struct sockbuf *sb = &so->so_rcv; 1271 struct protosw *pr = so->so_proto; 1272 struct sockbuf asb; 1273 | 1212 } 1213 } 1214 if ((flags & MSG_PEEK) == 0) { 1215 if (m == NULL) { 1216 /* 1217 * First part is an inline SB_EMPTY_FIXUP(). Second 1218 * part makes sure sb_lastrecord is up-to-date if 1219 * there is still data in the socket buffer. --- 52 unchanged lines hidden (view full) --- 1272void 1273sorflush(so) 1274 struct socket *so; 1275{ 1276 struct sockbuf *sb = &so->so_rcv; 1277 struct protosw *pr = so->so_proto; 1278 struct sockbuf asb; 1279 |
1280 /* 1281 * XXXRW: This is quite ugly. The existing code made a copy of the 1282 * socket buffer, then zero'd the original to clear the buffer 1283 * fields. However, with mutexes in the socket buffer, this causes 1284 * problems. We only clear the zeroable bits of the original; 1285 * however, we have to initialize and destroy the mutex in the copy 1286 * so that dom_dispose() and sbrelease() can lock t as needed. 1287 */ |
|
1274 SOCKBUF_LOCK(sb); 1275 sb->sb_flags |= SB_NOINTR; 1276 (void) sblock(sb, M_WAITOK); | 1288 SOCKBUF_LOCK(sb); 1289 sb->sb_flags |= SB_NOINTR; 1290 (void) sblock(sb, M_WAITOK); |
1277 socantrcvmore(so); | 1291 /* 1292 * socantrcvmore_locked() drops the socket buffer mutex so that it 1293 * can safely perform wakeups. Re-acquire the mutex before 1294 * continuing. 1295 */ 1296 socantrcvmore_locked(so); 1297 SOCKBUF_LOCK(sb); |
1278 sbunlock(sb); | 1298 sbunlock(sb); |
1279 asb = *sb; | |
1280 /* | 1299 /* |
1281 * Invalidate/clear most of the sockbuf structure, but keep 1282 * its selinfo structure valid. | 1300 * Invalidate/clear most of the sockbuf structure, but leave 1301 * selinfo and mutex data unchanged. |
1283 */ | 1302 */ |
1303 bzero(&asb, offsetof(struct sockbuf, sb_startzero)); 1304 bcopy(&sb->sb_startzero, &asb.sb_startzero, 1305 sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); |
|
1284 bzero(&sb->sb_startzero, 1285 sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); 1286 SOCKBUF_UNLOCK(sb); 1287 | 1306 bzero(&sb->sb_startzero, 1307 sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); 1308 SOCKBUF_UNLOCK(sb); 1309 |
1310 SOCKBUF_LOCK_INIT(&asb, "so_rcv"); |
|
1288 if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose != NULL) 1289 (*pr->pr_domain->dom_dispose)(asb.sb_mb); 1290 sbrelease(&asb, so); | 1311 if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose != NULL) 1312 (*pr->pr_domain->dom_dispose)(asb.sb_mb); 1313 sbrelease(&asb, so); |
1314 SOCKBUF_LOCK_DESTROY(&asb); |
|
1291} 1292 1293#ifdef INET 1294static int 1295do_setopt_accept_filter(so, sopt) 1296 struct socket *so; 1297 struct sockopt *sopt; 1298{ --- 751 unchanged lines hidden --- | 1315} 1316 1317#ifdef INET 1318static int 1319do_setopt_accept_filter(so, sopt) 1320 struct socket *so; 1321 struct sockopt *sopt; 1322{ --- 751 unchanged lines hidden --- |