accf_data.c revision 95759
1139749Simp/*- 2122526Ssimokawa * Copyright (c) 2000 Alfred Perlstein <alfred@FreeBSD.org> 3122526Ssimokawa * All rights reserved. 4103285Sikob * 5103285Sikob * Redistribution and use in source and binary forms, with or without 6103285Sikob * modification, are permitted provided that the following conditions 7103285Sikob * are met: 8103285Sikob * 1. Redistributions of source code must retain the above copyright 9103285Sikob * notice, this list of conditions and the following disclaimer. 10103285Sikob * 2. Redistributions in binary form must reproduce the above copyright 11103285Sikob * notice, this list of conditions and the following disclaimer in the 12103285Sikob * documentation and/or other materials provided with the distribution. 13103285Sikob * 14103285Sikob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15103285Sikob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16103285Sikob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17103285Sikob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18103285Sikob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19103285Sikob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20103285Sikob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22103285Sikob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23103285Sikob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24103285Sikob * SUCH DAMAGE. 25103285Sikob * 26103285Sikob * $FreeBSD: head/sys/netinet/accf_data.c 95759 2002-04-30 01:54:54Z tanimura $ 27103285Sikob */ 28103285Sikob 29103285Sikob#define ACCEPT_FILTER_MOD 30103285Sikob 31103285Sikob#include <sys/param.h> 32103285Sikob#include <sys/kernel.h> 33103285Sikob#include <sys/lock.h> 34103285Sikob#include <sys/sysctl.h> 35103285Sikob#include <sys/signalvar.h> 36103285Sikob#include <sys/socketvar.h> 37103285Sikob#include <sys/sx.h> 38103285Sikob 39103285Sikob/* accept filter that holds a socket until data arrives */ 40103285Sikob 41103285Sikobstatic void sohasdata(struct socket *so, void *arg, int waitflag); 42127468Ssimokawa 43103285Sikobstatic struct accept_filter accf_data_filter = { 44103285Sikob "dataready", 45103285Sikob sohasdata, 46127468Ssimokawa NULL, 47117126Sscottl NULL 48117126Sscottl}; 49117732Ssimokawa 50103285Sikobstatic moduledata_t accf_data_mod = { 51127468Ssimokawa "accf_data", 52112136Ssimokawa accept_filt_generic_mod_event, 53112136Ssimokawa &accf_data_filter 54103285Sikob}; 55127468Ssimokawa 56127468SsimokawaDECLARE_MODULE(accf_data, accf_data_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); 57127468Ssimokawa 58127468Ssimokawastatic void 59127468Ssimokawasohasdata(struct socket *so, void *arg, int waitflag) 60127468Ssimokawa{ 61127468Ssimokawa 62127468Ssimokawa SIGIO_SLOCK(); 63127468Ssimokawa if (!soreadable(so)) { 64127468Ssimokawa SIGIO_SUNLOCK(); 65127468Ssimokawa return; 66127468Ssimokawa } 67127468Ssimokawa 68127468Ssimokawa so->so_upcall = NULL; 69127468Ssimokawa so->so_rcv.sb_flags &= ~SB_UPCALL; 70103285Sikob soisconnected_locked(so); 71103285Sikob SIGIO_SUNLOCK(); 72103285Sikob return; 73103285Sikob} 74103285Sikob