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