accf_data.c revision 95552
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 *	$FreeBSD: head/sys/netinet/accf_data.c 95552 2002-04-27 08:24:29Z tanimura $
2761837Salfred */
2861837Salfred
2961837Salfred#define ACCEPT_FILTER_MOD
3061837Salfred
3161837Salfred#include <sys/param.h>
3265643Salfred#include <sys/sysctl.h>
3361837Salfred#include <sys/kernel.h>
3461837Salfred#include <sys/socketvar.h>
3561837Salfred
3661837Salfred/* accept filter that holds a socket until data arrives */
3761837Salfred
3861837Salfredstatic void	sohasdata(struct socket *so, void *arg, int waitflag);
3961837Salfred
4061837Salfredstatic struct accept_filter accf_data_filter = {
4161837Salfred	"dataready",
4261837Salfred	sohasdata,
4361837Salfred	NULL,
4461837Salfred	NULL
4561837Salfred};
4661837Salfred
4761837Salfredstatic moduledata_t accf_data_mod = {
4861837Salfred	"accf_data",
4961837Salfred	accept_filt_generic_mod_event,
5061837Salfred	&accf_data_filter
5161837Salfred};
5261837Salfred
5361837SalfredDECLARE_MODULE(accf_data, accf_data_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
5461837Salfred
5561837Salfredstatic void
5661837Salfredsohasdata(struct socket *so, void *arg, int waitflag)
5761837Salfred{
5861837Salfred
5995552Stanimura	SIGIO_SLOCK();
6061837Salfred	if (!soreadable(so)) {
6195552Stanimura		SIGIO_SUNLOCK();
6261837Salfred		return;
6361837Salfred	}
6461837Salfred
6561837Salfred	so->so_upcall = NULL;
6661837Salfred	so->so_rcv.sb_flags &= ~SB_UPCALL;
6795552Stanimura	soisconnected_locked(so);
6895552Stanimura	SIGIO_SUNLOCK();
6961837Salfred	return;
7061837Salfred}
71