build: Rewrite the build system to be nicer.
[fwd] / chan.h
1 /* -*-c-*-
2 *
3 * Channel management
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
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.
16 *
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.
21 *
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
27 #ifndef CHAN_H
28 #define CHAN_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /*----- Header files ------------------------------------------------------*/
35
36 #include <mLib/sel.h>
37
38 /*----- Magic numbers -----------------------------------------------------*/
39
40 #define CHAN_BUFSZ 4096
41
42 /*----- Data structures ---------------------------------------------------*/
43
44 typedef struct chan {
45 unsigned base, len; /* Base and length of data */
46 unsigned f; /* Various interesting flags */
47 void (*func)(void */*p*/); /* Function to call on closure */
48 void *p; /* Argument to pass function */
49 sel_file r, w; /* Reader and writer selectors */
50 char buf[CHAN_BUFSZ]; /* The actual data buffer */
51 } chan;
52
53 #define CHANF_CLOSE 1u /* Close channel when buffer empty */
54 #define CHANF_READY 2u /* The channel destination exists */
55
56 /*----- Functions provided ------------------------------------------------*/
57
58 /* --- @chan_close@ --- *
59 *
60 * Arguments: @chan *c@ = pointer to channel
61 *
62 * Returns: ---
63 *
64 * Use: Closes down a channel prematurely.
65 */
66
67 extern void chan_close(chan */*c*/);
68
69 /* --- @chan_dest@ --- *
70 *
71 * Arguments: @chan *c@ = pointer to channel
72 * @int fd@ = destination file descriptor for channel
73 *
74 * Returns: ---
75 *
76 * Use: Sets the channel's destination so it knows where to put
77 * data.
78 */
79
80 extern void chan_dest(chan */*c*/, int /*fd*/);
81
82 /* --- @chan_open@ --- *
83 *
84 * Arguments: @chan *c@ = pointer to channel to open
85 * @int from, to@ = source and destination file descriptors
86 * @void (*func)(void *p)@ = function to call on closure
87 * @void *p@ = argument to pass to function
88 *
89 * Returns: ---
90 *
91 * Use: Opens a channel. Data is copied from the source to the
92 * destination. The @to@ argument may be @-1@ if the file
93 * descriptor isn't known yet.
94 */
95
96 extern void chan_open(chan */*c*/, int /*from*/, int /*to*/,
97 void (*/*func*/)(void */*p*/), void */*p*/);
98
99 /*----- That's all, folks -------------------------------------------------*/
100
101 #ifdef __cplusplus
102 }
103 #endif
104
105 #endif