home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / amitcp-3.0ß2.lha / AmiTCP / src / amitcp / kern / uipc_socket2.c < prev    next >
C/C++ Source or Header  |  1993-12-18  |  25KB  |  948 lines

  1. RCS_ID_C="$Id: uipc_socket2.c,v 1.23 1993/12/18 15:28:09 jraja Exp $";
  2. /*
  3.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  4.  *                    Helsinki University of Technology, Finland.
  5.  *                    All rights reserved.
  6.  *
  7.  * HISTORY
  8.  * $Log: uipc_socket2.c,v $
  9.  * Revision 1.23  1993/12/18  15:28:09  jraja
  10.  * Disabled code using M_EOR, unless USE_M_EOR is defined.
  11.  *
  12.  * Revision 1.22  1993/11/17  12:14:31  jraja
  13.  * Added check for the SB_SEL flag to the sowakeup() to prevent unnecessary
  14.  * calls to selwakeup().
  15.  *
  16.  * Revision 1.21  1993/11/17  09:21:47  jraja
  17.  * Added setting of SB_SEL to sbselqueue(), so that protocols would notify us.
  18.  * Added clearing of that flag in sowakeup() to prevent extra notifications.
  19.  *
  20.  * Revision 1.20  1993/06/04  11:16:15  jraja
  21.  * Fixes for first public release.
  22.  *
  23.  * Revision 1.19  1993/05/17  01:07:47  ppessi
  24.  * Changed RCS version.
  25.  *
  26.  * Revision 1.18  1993/04/26  11:54:52  too
  27.  * Changed include paths of amiga_api.h, amiga_libcallentry.h and amiga_raf.h
  28.  * from kern to api
  29.  *
  30.  * Revision 1.17  93/04/24  22:45:56  22:45:56  jraja (Jarno Tapio Rajahalme)
  31.  * Removed Define for USECLUSTERS
  32.  * 
  33.  * Revision 1.16  93/04/24  17:52:35  17:52:35  jraja (Jarno Tapio Rajahalme)
  34.  * Changed MCLBYTES to mbconf.mclbytes.
  35.  * 
  36.  * Revision 1.15  93/04/12  00:38:28  00:38:28  jraja (Jarno Tapio Rajahalme)
  37.  * Added #include <kern/amiga_includes.h> and <kern/amiga_api.h> for Signal().
  38.  * 
  39.  * Revision 1.14  93/04/12  00:29:36  00:29:36  jraja (Jarno Tapio Rajahalme)
  40.  * Added signalling of the task (SIGIO).
  41.  * 
  42.  * Revision 1.13  93/04/06  15:16:21  15:16:21  jraja (Jarno Tapio Rajahalme)
  43.  * Changed spl function return value storage to spl_t,
  44.  * changed bcopys and bzeros to aligned and/or const when possible,
  45.  * added inclusion of conf.h to every .c file.
  46.  * 
  47.  * Revision 1.12  93/03/17  12:07:33  12:07:33  jraja (Jarno Tapio Rajahalme)
  48.  * Fixed tsleep() call to find socket base if necessary and to give NULL
  49.  * timeout if timeval is all zeroes.
  50.  * 
  51.  * Revision 1.11  93/03/05  21:11:20  21:11:20  jraja (Jarno Tapio Rajahalme)
  52.  * Fixed includes (again).
  53.  * 
  54.  * Revision 1.10  93/03/04  09:51:35  09:51:35  jraja (Jarno Tapio Rajahalme)
  55.  * Removed some redundant includes.
  56.  * 
  57.  * Revision 1.9  93/03/03  16:12:10  16:12:10  jraja (Jarno Tapio Rajahalme)
  58.  * Changed sonewconn1() to sonewconn().
  59.  * 
  60.  * Revision 1.8  93/03/02  17:35:07  17:35:07  too (Tomi Ollila)
  61.  * Changed some %d:s to %ld:s.. compiled when SOCKBUF_DEBUG is defined.
  62.  * 
  63.  * Revision 1.7  93/02/27  11:04:08  11:04:08  too (Tomi Ollila)
  64.  * Added prototypes.
  65.  * 
  66.  * Revision 1.6  93/02/25  13:02:06  13:02:06  too (Tomi Ollila)
  67.  * Added static inlines, sys/cdefs etc.
  68.  * 
  69.  * Revision 1.5  93/02/24  16:33:56  16:33:56  too (Tomi Ollila)
  70.  * Compiles.
  71.  * 
  72.  * Revision 1.4  93/02/23  11:39:45  11:39:45  too (Tomi Ollila)
  73.  * added SocketBase pointer to sbwait() and sblock(), now shoud work w/ AmiTCP
  74.  * 
  75.  * Revision 1.3  93/01/09  12:57:35  12:57:35  jraja (Jarno Tapio Rajahalme)
  76.  * Added #ifdef USECLUSTERS to disable cluster dependant code.
  77.  * 
  78.  * Revision 1.2  92/11/20  15:14:52  15:14:52  jraja (Jarno Tapio Rajahalme)
  79.  * Added #ifndef AMITCP's to make this compile.
  80.  * 
  81.  * Revision 1.1  92/11/19  12:07:33  12:07:33  jraja (Jarno Tapio Rajahalme)
  82.  * Initial revision
  83.  * 
  84.  *
  85.  */
  86.  
  87. /* 
  88.  * Mach Operating System
  89.  * Copyright (c) 1992 Carnegie Mellon University
  90.  * All Rights Reserved.
  91.  * 
  92.  * Permission to use, copy, modify and distribute this software and its
  93.  * documentation is hereby granted, provided that both the copyright
  94.  * notice and this permission notice appear in all copies of the
  95.  * software, derivative works or modified versions, and any portions
  96.  * thereof, and that both notices appear in supporting documentation.
  97.  * 
  98.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  99.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  100.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  101.  * 
  102.  * Carnegie Mellon requests users of this software to return to
  103.  * 
  104.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  105.  *  School of Computer Science
  106.  *  Carnegie Mellon University
  107.  *  Pittsburgh PA 15213-3890
  108.  * 
  109.  * any improvements or extensions that they make and grant Carnegie Mellon 
  110.  * the rights to redistribute these changes.
  111.  */
  112. /*
  113.  * HISTORY
  114.  * Log:    uipc_socket2.c,v
  115.  * Revision 2.1  92/04/21  17:13:26  rwd
  116.  * BSDSS
  117.  * 
  118.  *
  119.  */
  120.  
  121. /*
  122.  * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
  123.  * All rights reserved.
  124.  *
  125.  * Redistribution and use in source and binary forms, with or without
  126.  * modification, are permitted provided that the following conditions
  127.  * are met:
  128.  * 1. Redistributions of source code must retain the above copyright
  129.  *    notice, this list of conditions and the following disclaimer.
  130.  * 2. Redistributions in binary form must reproduce the above copyright
  131.  *    notice, this list of conditions and the following disclaimer in the
  132.  *    documentation and/or other materials provided with the distribution.
  133.  * 3. All advertising materials mentioning features or use of this software
  134.  *    must display the following acknowledgement:
  135.  *    This product includes software developed by the University of
  136.  *    California, Berkeley and its contributors.
  137.  * 4. Neither the name of the University nor the names of its contributors
  138.  *    may be used to endorse or promote products derived from this software
  139.  *    without specific prior written permission.
  140.  *
  141.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  142.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  143.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  144.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  145.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  146.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  147.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  148.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  149.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  150.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  151.  * SUCH DAMAGE.
  152.  *
  153.  *    @(#)uipc_socket2.c    7.17 (Berkeley) 5/4/91
  154.  */
  155.  
  156. #include <conf.h>
  157.  
  158. #include <sys/param.h>
  159. #include <sys/systm.h>
  160. #include <sys/malloc.h>
  161. #include <sys/mbuf.h>
  162. #include <sys/protosw.h>
  163. #include <sys/socket.h>
  164. #include <sys/socketvar.h>
  165. #include <sys/synch.h>
  166.  
  167. #include <api/amiga_api.h>
  168. #include <kern/amiga_includes.h>
  169.  
  170. #include <kern/uipc_socket2_protos.h>
  171. #include <kern/amiga_select_protos.h>
  172.  
  173. /*
  174.  * Primitive routines for operating on sockets and socket buffers
  175.  */
  176.  
  177. /* strings for sleep message: */
  178. char    netio[] = "netio";
  179. char    netcon[] = "netcon";
  180. char    netcls[] = "netcls";
  181.  
  182. u_long    sb_max = SB_MAX;        /* patchable */
  183.  
  184. /*
  185.  * Procedures to manipulate state flags of socket
  186.  * and do appropriate wakeups.  Normal sequence from the
  187.  * active (originating) side is that soisconnecting() is
  188.  * called during processing of connect() call,
  189.  * resulting in an eventual call to soisconnected() if/when the
  190.  * connection is established.  When the connection is torn down
  191.  * soisdisconnecting() is called during processing of disconnect() call,
  192.  * and soisdisconnected() is called when the connection to the peer
  193.  * is totally severed.  The semantics of these routines are such that
  194.  * connectionless protocols can call soisconnected() and soisdisconnected()
  195.  * only, bypassing the in-progress calls when setting up a ``connection''
  196.  * takes no time.
  197.  *
  198.  * From the passive side, a socket is created with
  199.  * two queues of sockets: so_q0 for connections in progress
  200.  * and so_q for connections already made and awaiting user acceptance.
  201.  * As a protocol is preparing incoming connections, it creates a socket
  202.  * structure queued on so_q0 by calling sonewconn().  When the connection
  203.  * is established, soisconnected() is called, and transfers the
  204.  * socket structure to so_q, making it available to accept().
  205.  * 
  206.  * If a socket is closed with sockets on either
  207.  * so_q0 or so_q, these sockets are dropped.
  208.  *
  209.  * If