07d71f34 |
1 | /* -*-c-*- |
2 | * |
7481fc9c |
3 | * $Id: endpt.h,v 1.3 2004/04/08 01:36:25 mdw Exp $ |
07d71f34 |
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 | |
07d71f34 |
29 | #ifndef ENDPT_H |
30 | #define ENDPT_H |
31 | |
32 | #ifdef __cplusplus |
33 | extern "C" { |
34 | #endif |
35 | |
36 | /*----- Header files ------------------------------------------------------*/ |
37 | |
38 | #ifndef REFFD_H |
39 | # include "reffd.h" |
40 | #endif |
41 | |
42 | /*----- Data structures ---------------------------------------------------*/ |
43 | |
44 | /* --- Basic endpoint structure --- */ |
45 | |
46 | typedef struct endpt { |
47 | struct endpt_ops *ops; /* Pointer to operations table */ |
48 | struct endpt *other; /* Pointer to sibling endpoint */ |
49 | unsigned f; /* Various flags */ |
50 | struct tango *t; /* Private data structure */ |
51 | reffd *in, *out; /* File descriptors */ |
52 | } endpt; |
53 | |
54 | /* --- Endpoint flags --- */ |
55 | |
56 | #define EPF_PENDING 1u /* Endpoint creation in progress */ |
57 | #define EPF_FILE 2u /* Endpoint smells like a file */ |
58 | |
59 | /* --- Endpoint operations table --- */ |
60 | |
61 | typedef struct endpt_ops { |
62 | |
63 | /* --- @attach@ --- * |
64 | * |
65 | * Arguments: @endpt *e@ = pointer to endpoint to be attached |
66 | * @reffd *in, *out@ = input and output file descriptors |
67 | * |
68 | * Returns: --- |
69 | * |
70 | * Use: Instructs a non-file endpoint to attach itself to a pair of |
71 | * files. |
72 | */ |
73 | |
74 | void (*attach)(endpt */*e*/, reffd */*in*/, reffd */*out*/); |
75 | |
28d2517c |
76 | /* --- @file@ --- * |
77 | * |
78 | * Arguments: @endpt *e@ = pointer to endpoint in question |
79 | * @endpt *f@ = pointer to a file endpoint |
80 | * |
81 | * Returns: --- |
82 | * |
83 | * Use: Informs a non-file endpoint of a file endpoint which will |
84 | * want to be closed when it's finished with. At that time, the |
85 | * endpoint should arrange to have both itself and its partner |
86 | * closed. If no file is registered, the endpoint manager will |
87 | * close both endpoints itself. |
88 | */ |
89 | |
90 | void (*file)(endpt */*e*/, endpt */*f*/); |
91 | |
07d71f34 |
92 | /* --- @wclose@ --- * |
93 | * |
94 | * Arguments: @endpt *e@ = endpoint to be partially closed |
95 | * |
96 | * Returns: --- |
97 | * |
98 | * Use: Announces that the endpoint will not be written to any more. |
99 | */ |
100 | |
101 | void (*wclose)(endpt */*e*/); |
102 | |
103 | /* --- @close@ --- * |
104 | * |
105 | * Arguments: @endpt *e@ = endpoint to be closed |
106 | * |
107 | * Returns: --- |
108 | * |
109 | * Use: Completely closes an endpoint. The endpoint's data may be |
110 | * freed, although some endpoints may wish to delay freeing for |
111 | * some reason. |
112 | */ |
113 | |
114 | void (*close)(endpt */*e*/); |
115 | |
116 | } endpt_ops; |
117 | |
118 | /*----- Functions provided ------------------------------------------------*/ |
119 | |
120 | /* --- @endpt_kill@ --- * |
121 | * |
122 | * Arguments: @endpt *a@ = an endpoint |
123 | * |
124 | * Returns: --- |
125 | * |
126 | * Use: Kills an endpoint. If the endpoint is joined to another, the |
127 | * other endpoint is also killed, as is the connection between |
128 | * them (and that's the tricky bit). |
129 | */ |
130 | |
131 | extern void endpt_kill(endpt */*a*/); |
132 | |
133 | /* --- @endpt_killall@ --- * |
134 | * |
135 | * Arguments: --- |
136 | * |
137 | * Returns: --- |
138 | * |
139 | * Use: Destroys all current endpoint connections. Used when |
140 | * shutting down. |
141 | */ |
142 | |
143 | extern void endpt_killall(void); |
144 | |
145 | /* --- @endpt_join@ --- * |
146 | * |
147 | * Arguments: @endpt *a@ = pointer to first endpoint |
148 | * @endpt *b@ = pointer to second endpoint |
149 | * |
150 | * Returns: --- |
151 | * |
152 | * Use: Joins two endpoints together. |
153 | */ |
154 | |
155 | extern void endpt_join(endpt */*a*/, endpt */*b*/); |
156 | |
157 | /*----- That's all, folks -------------------------------------------------*/ |
158 | |
159 | #ifdef __cplusplus |
160 | } |
161 | #endif |
162 | |
163 | #endif |