uipc_socket.c (58225) | uipc_socket.c (59288) |
---|---|
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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 | 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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 |
34 * $FreeBSD: head/sys/kern/uipc_socket.c 58225 2000-03-18 08:56:56Z fenner $ | 34 * $FreeBSD: head/sys/kern/uipc_socket.c 59288 2000-04-16 18:53:38Z jlemon $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/fcntl.h> 40#include <sys/malloc.h> 41#include <sys/mbuf.h> 42#include <sys/domain.h> | 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/fcntl.h> 40#include <sys/malloc.h> 41#include <sys/mbuf.h> 42#include <sys/domain.h> |
43#include <sys/file.h> /* for struct knote */ |
|
43#include <sys/kernel.h> 44#include <sys/malloc.h> | 44#include <sys/kernel.h> 45#include <sys/malloc.h> |
46#include <sys/event.h> |
|
45#include <sys/poll.h> 46#include <sys/proc.h> 47#include <sys/protosw.h> 48#include <sys/socket.h> 49#include <sys/socketvar.h> 50#include <sys/resourcevar.h> 51#include <sys/signalvar.h> 52#include <sys/sysctl.h> 53#include <sys/uio.h> 54#include <vm/vm_zone.h> 55 56#include <machine/limits.h> 57 | 47#include <sys/poll.h> 48#include <sys/proc.h> 49#include <sys/protosw.h> 50#include <sys/socket.h> 51#include <sys/socketvar.h> 52#include <sys/resourcevar.h> 53#include <sys/signalvar.h> 54#include <sys/sysctl.h> 55#include <sys/uio.h> 56#include <vm/vm_zone.h> 57 58#include <machine/limits.h> 59 |
60static int filt_sorattach(struct knote *kn); 61static void filt_sordetach(struct knote *kn); 62static int filt_soread(struct knote *kn, long hint); 63static int filt_sowattach(struct knote *kn); 64static void filt_sowdetach(struct knote *kn); 65static int filt_sowrite(struct knote *kn, long hint); 66static int filt_solisten(struct knote *kn, long hint); 67 68static struct filterops solisten_filtops = 69 { 1, filt_sorattach, filt_sordetach, filt_solisten }; 70 71struct filterops so_rwfiltops[] = { 72 { 1, filt_sorattach, filt_sordetach, filt_soread }, 73 { 1, filt_sowattach, filt_sowdetach, filt_sowrite }, 74}; 75 |
|
58struct vm_zone *socket_zone; 59so_gen_t so_gencnt; /* generation count for sockets */ 60 61MALLOC_DEFINE(M_SONAME, "soname", "socket name"); 62MALLOC_DEFINE(M_PCB, "pcb", "protocol control block"); 63 64SYSCTL_DECL(_kern_ipc); 65 --- 1317 unchanged lines hidden (view full) --- 1383 selrecord(p, &so->so_snd.sb_sel); 1384 so->so_snd.sb_flags |= SB_SEL; 1385 } 1386 } 1387 1388 splx(s); 1389 return (revents); 1390} | 76struct vm_zone *socket_zone; 77so_gen_t so_gencnt; /* generation count for sockets */ 78 79MALLOC_DEFINE(M_SONAME, "soname", "socket name"); 80MALLOC_DEFINE(M_PCB, "pcb", "protocol control block"); 81 82SYSCTL_DECL(_kern_ipc); 83 --- 1317 unchanged lines hidden (view full) --- 1401 selrecord(p, &so->so_snd.sb_sel); 1402 so->so_snd.sb_flags |= SB_SEL; 1403 } 1404 } 1405 1406 splx(s); 1407 return (revents); 1408} |
1409 1410static int 1411filt_sorattach(struct knote *kn) 1412{ 1413 struct socket *so = (struct socket *)kn->kn_fp->f_data; 1414 int s = splnet(); 1415 1416 if (so->so_options & SO_ACCEPTCONN) 1417 kn->kn_fop = &solisten_filtops; 1418 SLIST_INSERT_HEAD(&so->so_rcv.sb_sel.si_note, kn, kn_selnext); 1419 so->so_rcv.sb_flags |= SB_KNOTE; 1420 splx(s); 1421 return (0); 1422} 1423 1424static void 1425filt_sordetach(struct knote *kn) 1426{ 1427 struct socket *so = (struct socket *)kn->kn_fp->f_data; 1428 int s = splnet(); 1429 1430 SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext); 1431 if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note)) 1432 so->so_rcv.sb_flags &= ~SB_KNOTE; 1433 splx(s); 1434} 1435 1436/*ARGSUSED*/ 1437static int 1438filt_soread(struct knote *kn, long hint) 1439{ 1440 struct socket *so = (struct socket *)kn->kn_fp->f_data; 1441 1442 kn->kn_data = so->so_rcv.sb_cc; 1443 if (so->so_state & SS_CANTRCVMORE) { 1444 kn->kn_flags |= EV_EOF; 1445 return (1); 1446 } 1447 return (kn->kn_data > 0); 1448} 1449 1450static int 1451filt_sowattach(struct knote *kn) 1452{ 1453 struct socket *so = (struct socket *)kn->kn_fp->f_data; 1454 int s = splnet(); 1455 1456 SLIST_INSERT_HEAD(&so->so_snd.sb_sel.si_note, kn, kn_selnext); 1457 so->so_snd.sb_flags |= SB_KNOTE; 1458 splx(s); 1459 return (0); 1460} 1461 1462static void 1463filt_sowdetach(struct knote *kn) 1464{ 1465 struct socket *so = (struct socket *)kn->kn_fp->f_data; 1466 int s = splnet(); 1467 1468 SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext); 1469 if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note)) 1470 so->so_snd.sb_flags &= ~SB_KNOTE; 1471 splx(s); 1472} 1473 1474/*ARGSUSED*/ 1475static int 1476filt_sowrite(struct knote *kn, long hint) 1477{ 1478 struct socket *so = (struct socket *)kn->kn_fp->f_data; 1479 1480 kn->kn_data = sbspace(&so->so_snd); 1481 if (so->so_state & SS_CANTSENDMORE) { 1482 kn->kn_flags |= EV_EOF; 1483 return (1); 1484 } 1485 if (((so->so_state & SS_ISCONNECTED) == 0) && 1486 (so->so_proto->pr_flags & PR_CONNREQUIRED)) 1487 return (0); 1488 return (kn->kn_data >= so->so_snd.sb_lowat); 1489} 1490 1491/*ARGSUSED*/ 1492static int 1493filt_solisten(struct knote *kn, long hint) 1494{ 1495 struct socket *so = (struct socket *)kn->kn_fp->f_data; 1496 1497 kn->kn_data = so->so_qlen - so->so_incqlen; 1498 return (! TAILQ_EMPTY(&so->so_comp)); 1499} |
|