chiark / gitweb /
Infrastructure for the new design.
[fwd] / endpt.h
1 /* -*-c-*-
2  *
3  * $Id: endpt.h,v 1.1 1999/07/26 23:33:01 mdw Exp $
4  *
5  * Generic endpoint abstraction
6  *
7  * (c) 1999 Straylight/Edgeware
8  */
9
10 /*----- Licensing notice --------------------------------------------------* 
11  *
12  * This file is part of the `fw' port forwarder.
13  *
14  * `fw' is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  * 
19  * `fw' is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with `fw'; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27  */
28
29 /*----- Revision history --------------------------------------------------* 
30  *
31  * $Log: endpt.h,v $
32  * Revision 1.1  1999/07/26 23:33:01  mdw
33  * Infrastructure for the new design.
34  *
35  */
36
37 #ifndef ENDPT_H
38 #define ENDPT_H
39
40 #ifdef __cplusplus
41   extern "C" {
42 #endif
43
44 /*----- Header files ------------------------------------------------------*/
45
46 #ifndef REFFD_H
47 #  include "reffd.h"
48 #endif
49
50 /*----- Data structures ---------------------------------------------------*/
51
52 /* --- Basic endpoint structure --- */
53
54 typedef struct endpt {
55   struct endpt_ops *ops;                /* Pointer to operations table */
56   struct endpt *other;                  /* Pointer to sibling endpoint */
57   unsigned f;                           /* Various flags */
58   struct tango *t;                      /* Private data structure */
59   reffd *in, *out;                      /* File descriptors */
60 } endpt;
61
62 /* --- Endpoint flags --- */
63
64 #define EPF_PENDING 1u                  /* Endpoint creation in progress */
65 #define EPF_FILE 2u                     /* Endpoint smells like a file */
66
67 /* --- Endpoint operations table --- */
68
69 typedef struct endpt_ops {
70
71   /* --- @attach@ --- *
72    *
73    * Arguments: @endpt *e@ = pointer to endpoint to be attached
74    *            @reffd *in, *out@ = input and output file descriptors
75    *
76    * Returns:   ---
77    *
78    * Use:       Instructs a non-file endpoint to attach itself to a pair of
79    *            files.
80    */
81
82   void (*attach)(endpt */*e*/, reffd */*in*/, reffd */*out*/);
83
84   /* --- @wclose@ --- *
85    *
86    * Arguments: @endpt *e@ = endpoint to be partially closed
87    *
88    * Returns:   ---
89    *
90    * Use:       Announces that the endpoint will not be written to any more.
91    */
92
93   void (*wclose)(endpt */*e*/);
94
95   /* --- @close@ --- *
96    *
97    * Arguments: @endpt *e@ = endpoint to be closed
98    *
99    * Returns:   ---
100    *
101    * Use:       Completely closes an endpoint.  The endpoint's data may be
102    *            freed, although some endpoints may wish to delay freeing for
103    *            some reason.
104    */
105
106   void (*close)(endpt */*e*/);
107
108 } endpt_ops;
109
110 /*----- Functions provided ------------------------------------------------*/
111
112 /* --- @endpt_kill@ --- *
113  *
114  * Arguments:   @endpt *a@ = an endpoint
115  *
116  * Returns:     ---
117  *
118  * Use:         Kills an endpoint.  If the endpoint is joined to another, the
119  *              other endpoint is also killed, as is the connection between
120  *              them (and that's the tricky bit).
121  */
122
123 extern void endpt_kill(endpt */*a*/);
124
125 /* --- @endpt_killall@ --- *
126  *
127  * Arguments:   ---
128  *
129  * Returns:     ---
130  *
131  * Use:         Destroys all current endpoint connections.  Used when
132  *              shutting down.
133  */
134
135 extern void endpt_killall(void);
136
137 /* --- @endpt_join@ --- *
138  *
139  * Arguments:   @endpt *a@ = pointer to first endpoint
140  *              @endpt *b@ = pointer to second endpoint
141  *
142  * Returns:     ---
143  *
144  * Use:         Joins two endpoints together.
145  */
146
147 extern void endpt_join(endpt */*a*/, endpt */*b*/);
148
149 /*----- That's all, folks -------------------------------------------------*/
150
151 #ifdef __cplusplus
152   }
153 #endif
154
155 #endif