3 * $Id: chan.h,v 1.1 1999/07/01 08:56:23 mdw Exp $
7 * (c) 1999 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the `fw' port forwarder.
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.
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.
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.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1999/07/01 08:56:23 mdw
44 /*----- Header files ------------------------------------------------------*/
48 /*----- Magic numbers -----------------------------------------------------*/
50 #define CHAN_BUFSZ 4096
52 /*----- Data structures ---------------------------------------------------*/
55 unsigned base
, len
; /* Base and length of data */
56 unsigned f
; /* Various interesting flags */
57 void (*func
)(void */
*p*/
); /* Function to call on closure */
58 void *p
; /* Argument to pass function */
59 sel_file r
, w
; /* Reader and writer selectors */
60 char buf
[CHAN_BUFSZ
]; /* The actual data buffer */
63 #define CHANF_CLOSE 1u /* Close channel when buffer empty */
64 #define CHANF_READY 2u /* The channel destination exists */
66 /*----- Functions provided ------------------------------------------------*/
68 /* --- @chan_close@ --- *
70 * Arguments: @chan *c@ = pointer to channel
74 * Use: Closes down a channel prematurely.
77 extern void chan_close(chan */
*c*/
);
79 /* --- @chan_dest@ --- *
81 * Arguments: @chan *c@ = pointer to channel
82 * @int fd@ = destination file descriptor for channel
86 * Use: Sets the channel's destination so it knows where to put
90 extern void chan_dest(chan */
*c*/
, int /*fd*/);
92 /* --- @chan_open@ --- *
94 * Arguments: @chan *c@ = pointer to channel to open
95 * @int from, to@ = source and destination file descriptors
96 * @void (*func)(void *p)@ = function to call on closure
97 * @void *p@ = argument to pass to function
101 * Use: Opens a channel. Data is copied from the source to the
102 * destination. The @to@ argument may be @-1@ if the file
103 * descriptor isn't known yet.
106 extern void chan_open(chan */
*c*/
, int /*from*/, int /*to*/,
107 void (*/
*func*/
)(void */
*p*/
), void */
*p*/
);
109 /*----- That's all, folks -------------------------------------------------*/