accf_data.c revision 65643
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 65643 2000-09-09 18:47:46Z alfred $
2761837Salfred */
2861837Salfred
2961837Salfred#define ACCEPT_FILTER_MOD
3061837Salfred
3161837Salfred#include <sys/param.h>
3265643Salfred#include <sys/sysctl.h>
3361837Salfred#include <sys/systm.h>
3461837Salfred#include <sys/sysproto.h>
3561837Salfred#include <sys/kernel.h>
3661837Salfred#include <sys/proc.h>
3761837Salfred#include <sys/malloc.h>
3861837Salfred#include <sys/unistd.h>
3961837Salfred#include <sys/file.h>
4061837Salfred#include <sys/fcntl.h>
4161837Salfred#include <sys/protosw.h>
4261837Salfred#include <sys/socket.h>
4361837Salfred#include <sys/socketvar.h>
4461837Salfred#include <sys/stat.h>
4561837Salfred#include <sys/mbuf.h>
4661837Salfred#include <sys/resource.h>
4761837Salfred#include <sys/sysent.h>
4861837Salfred#include <sys/resourcevar.h>
4961837Salfred
5061837Salfred/* accept filter that holds a socket until data arrives */
5161837Salfred
5261837Salfredstatic void	sohasdata(struct socket *so, void *arg, int waitflag);
5361837Salfred
5461837Salfredstatic struct accept_filter accf_data_filter = {
5561837Salfred	"dataready",
5661837Salfred	sohasdata,
5761837Salfred	NULL,
5861837Salfred	NULL
5961837Salfred};
6061837Salfred
6161837Salfredstatic moduledata_t accf_data_mod = {
6261837Salfred	"accf_data",
6361837Salfred	accept_filt_generic_mod_event,
6461837Salfred	&accf_data_filter
6561837Salfred};
6661837Salfred
6761837SalfredDECLARE_MODULE(accf_data, accf_data_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
6861837Salfred
6961837Salfredstatic void
7061837Salfredsohasdata(struct socket *so, void *arg, int waitflag)
7161837Salfred{
7261837Salfred
7361837Salfred	if (!soreadable(so)) {
7461837Salfred		return;
7561837Salfred	}
7661837Salfred
7761837Salfred	so->so_upcall = NULL;
7861837Salfred	so->so_rcv.sb_flags &= ~SB_UPCALL;
7961837Salfred	soisconnected(so);
8061837Salfred	return;
8161837Salfred}
82