accf_data.c revision 172467
1194246Smarius/*-
2194246Smarius * Copyright (c) 2000 Alfred Perlstein <alfred@FreeBSD.org>
3194246Smarius * All rights reserved.
4194246Smarius *
5194246Smarius * Redistribution and use in source and binary forms, with or without
6194246Smarius * modification, are permitted provided that the following conditions
7194246Smarius * are met:
8194246Smarius * 1. Redistributions of source code must retain the above copyright
9194246Smarius *    notice, this list of conditions and the following disclaimer.
10194246Smarius * 2. Redistributions in binary form must reproduce the above copyright
11194246Smarius *    notice, this list of conditions and the following disclaimer in the
12194246Smarius *    documentation and/or other materials provided with the distribution.
13194246Smarius *
14194246Smarius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15194246Smarius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16194246Smarius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17194246Smarius * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18194246Smarius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19194246Smarius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20194246Smarius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21194246Smarius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22194246Smarius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23194246Smarius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24194246Smarius * SUCH DAMAGE.
25194246Smarius */
26194246Smarius
27194246Smarius#include <sys/cdefs.h>
28194246Smarius__FBSDID("$FreeBSD: head/sys/netinet/accf_data.c 172467 2007-10-07 20:44:24Z silby $");
29194246Smarius
30194246Smarius#define ACCEPT_FILTER_MOD
31194246Smarius
32194246Smarius#include <sys/param.h>
33194246Smarius#include <sys/kernel.h>
34194246Smarius#include <sys/module.h>
35194246Smarius#include <sys/sysctl.h>
36194246Smarius#include <sys/signalvar.h>
37194246Smarius#include <sys/socketvar.h>
38194246Smarius
39194246Smarius/* accept filter that holds a socket until data arrives */
40194246Smarius
41194246Smariusstatic void	sohasdata(struct socket *so, void *arg, int waitflag);
42194246Smarius
43194246Smariusstatic struct accept_filter accf_data_filter = {
44194246Smarius	"dataready",
45194246Smarius	sohasdata,
46194246Smarius	NULL,
47194246Smarius	NULL
48194246Smarius};
49194246Smarius
50194246Smariusstatic moduledata_t accf_data_mod = {
51194246Smarius	"accf_data",
52194246Smarius	accept_filt_generic_mod_event,
53194246Smarius	&accf_data_filter
54194246Smarius};
55194246Smarius
56194246SmariusDECLARE_MODULE(accf_data, accf_data_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
57194246Smarius
58194246Smariusstatic void
59194246Smariussohasdata(struct socket *so, void *arg, int waitflag)
60194246Smarius{
61194246Smarius
62194246Smarius	if (!soreadable(so))
63194246Smarius		return;
64194246Smarius
65194246Smarius	so->so_upcall = NULL;
66194246Smarius	so->so_rcv.sb_flags &= ~SB_UPCALL;
67194246Smarius	soisconnected(so);
68194246Smarius	return;
69194246Smarius}
70194246Smarius