build: Rewrite the build system to be nicer.
[fwd] / chan.h
CommitLineData
e82f7154 1/* -*-c-*-
2 *
e82f7154 3 * Channel management
4 *
5f12a82a 5 * (c) 1999 Straylight/Edgeware
e82f7154 6 */
7
206212ca 8/*----- Licensing notice --------------------------------------------------*
e82f7154 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 *
e82f7154 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 *
e82f7154 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
e82f7154 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
44typedef 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
67extern 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
80extern 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
96extern 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