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