uipc_socket.c (175845) | uipc_socket.c (175968) |
---|---|
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 175845 2008-01-31 08:22:24Z rwatson $"); | 98__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 175968 2008-02-04 12:25:13Z rwatson $"); |
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> --- 1765 unchanged lines hidden (view full) --- 1872void 1873sorflush(struct socket *so) 1874{ 1875 struct sockbuf *sb = &so->so_rcv; 1876 struct protosw *pr = so->so_proto; 1877 struct sockbuf asb; 1878 1879 /* | 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> --- 1765 unchanged lines hidden (view full) --- 1872void 1873sorflush(struct socket *so) 1874{ 1875 struct sockbuf *sb = &so->so_rcv; 1876 struct protosw *pr = so->so_proto; 1877 struct sockbuf asb; 1878 1879 /* |
1880 * XXXRW: This is quite ugly. Previously, this code made a copy of 1881 * the socket buffer, then zero'd the original to clear the buffer 1882 * fields. However, with mutexes in the socket buffer, this causes 1883 * problems. We only clear the zeroable bits of the original; 1884 * however, we have to initialize and destroy the mutex in the copy 1885 * so that dom_dispose() and sbrelease() can lock t as needed. 1886 */ 1887 1888 /* | 1880 * In order to avoid calling dom_dispose with the socket buffer mutex 1881 * held, and in order to generally avoid holding the lock for a long 1882 * time, we make a copy of the socket buffer and clear the original 1883 * (except locks, state). The new socket buffer copy won't have 1884 * initialized locks so we can only call routines that won't use or 1885 * assert those locks. 1886 * |
1889 * Dislodge threads currently blocked in receive and wait to acquire 1890 * a lock against other simultaneous readers before clearing the 1891 * socket buffer. Don't let our acquire be interrupted by a signal 1892 * despite any existing socket disposition on interruptable waiting. 1893 */ 1894 socantrcvmore(so); 1895 (void) sblock(sb, SBL_WAIT | SBL_NOINTR); 1896 --- 5 unchanged lines hidden (view full) --- 1902 bzero(&asb, offsetof(struct sockbuf, sb_startzero)); 1903 bcopy(&sb->sb_startzero, &asb.sb_startzero, 1904 sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); 1905 bzero(&sb->sb_startzero, 1906 sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); 1907 SOCKBUF_UNLOCK(sb); 1908 sbunlock(sb); 1909 | 1887 * Dislodge threads currently blocked in receive and wait to acquire 1888 * a lock against other simultaneous readers before clearing the 1889 * socket buffer. Don't let our acquire be interrupted by a signal 1890 * despite any existing socket disposition on interruptable waiting. 1891 */ 1892 socantrcvmore(so); 1893 (void) sblock(sb, SBL_WAIT | SBL_NOINTR); 1894 --- 5 unchanged lines hidden (view full) --- 1900 bzero(&asb, offsetof(struct sockbuf, sb_startzero)); 1901 bcopy(&sb->sb_startzero, &asb.sb_startzero, 1902 sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); 1903 bzero(&sb->sb_startzero, 1904 sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); 1905 SOCKBUF_UNLOCK(sb); 1906 sbunlock(sb); 1907 |
1910 SOCKBUF_LOCK_INIT(&asb, "so_rcv"); | 1908 /* 1909 * Dispose of special rights and flush the socket buffer. Don't call 1910 * any unsafe routines (that rely on locks being initialized) on asb. 1911 */ |
1911 if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose != NULL) 1912 (*pr->pr_domain->dom_dispose)(asb.sb_mb); | 1912 if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose != NULL) 1913 (*pr->pr_domain->dom_dispose)(asb.sb_mb); |
1913 sbrelease(&asb, so); 1914 SOCKBUF_LOCK_DESTROY(&asb); | 1914 sbrelease_internal(&asb, so); |
1915} 1916 1917/* 1918 * Perhaps this routine, and sooptcopyout(), below, ought to come in an 1919 * additional variant to handle the case where the option value needs to be 1920 * some kind of integer, but not a specific size. In addition to their use 1921 * here, these functions are also called by the protocol-level pr_ctloutput() 1922 * routines. --- 1035 unchanged lines hidden --- | 1915} 1916 1917/* 1918 * Perhaps this routine, and sooptcopyout(), below, ought to come in an 1919 * additional variant to handle the case where the option value needs to be 1920 * some kind of integer, but not a specific size. In addition to their use 1921 * here, these functions are also called by the protocol-level pr_ctloutput() 1922 * routines. --- 1035 unchanged lines hidden --- |