161837Salfred/*-
261837Salfred * Copyright (c) 2000 Alfred Perlstein <alfred@FreeBSD.org>
361837Salfred * All rights reserved.
461837Salfred *
561837Salfred * Redistribution and use in source and binary forms, with or without
661837Salfred * modification, are permitted provided that the following conditions
761837Salfred * are met:
861837Salfred * 1. Redistributions of source code must retain the above copyright
961837Salfred *    notice, this list of conditions and the following disclaimer.
1061837Salfred * 2. Redistributions in binary form must reproduce the above copyright
1161837Salfred *    notice, this list of conditions and the following disclaimer in the
1261837Salfred *    documentation and/or other materials provided with the distribution.
1361837Salfred *
1461837Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1561837Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1661837Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1761837Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1861837Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1961837Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2061837Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2161837Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2261837Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2361837Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2461837Salfred * SUCH DAMAGE.
2561837Salfred */
2661837Salfred
27172467Ssilby#include <sys/cdefs.h>
28172467Ssilby__FBSDID("$FreeBSD: releng/10.3/sys/netinet/accf_data.c 193272 2009-06-01 21:17:03Z jhb $");
29172467Ssilby
3061837Salfred#define ACCEPT_FILTER_MOD
3161837Salfred
3261837Salfred#include <sys/param.h>
3395759Stanimura#include <sys/kernel.h>
34129880Sphk#include <sys/module.h>
3565643Salfred#include <sys/sysctl.h>
3695759Stanimura#include <sys/signalvar.h>
3761837Salfred#include <sys/socketvar.h>
3861837Salfred
3961837Salfred/* accept filter that holds a socket until data arrives */
4061837Salfred
41193272Sjhbstatic int	sohasdata(struct socket *so, void *arg, int waitflag);
4261837Salfred
4361837Salfredstatic struct accept_filter accf_data_filter = {
4461837Salfred	"dataready",
4561837Salfred	sohasdata,
4661837Salfred	NULL,
4761837Salfred	NULL
4861837Salfred};
4961837Salfred
5061837Salfredstatic moduledata_t accf_data_mod = {
5161837Salfred	"accf_data",
5261837Salfred	accept_filt_generic_mod_event,
5361837Salfred	&accf_data_filter
5461837Salfred};
5561837Salfred
5661837SalfredDECLARE_MODULE(accf_data, accf_data_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
5761837Salfred
58193272Sjhbstatic int
5961837Salfredsohasdata(struct socket *so, void *arg, int waitflag)
6061837Salfred{
6161837Salfred
6297658Stanimura	if (!soreadable(so))
63193272Sjhb		return (SU_OK);
6461837Salfred
65193272Sjhb	return (SU_ISCONNECTED);
6661837Salfred}
67