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