3 * $Id: reffd.h,v 1.2 2004/04/08 01:36:25 mdw Exp $
5 * Reference counted file descriptors
7 * (c) 1999 Straylight/Edgeware
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.
36 /*----- Header files ------------------------------------------------------*/
42 /*----- Data structures ---------------------------------------------------*/
44 typedef struct reffd {
47 void (*proc)(void */*p*/);
51 /*----- Functions provided ------------------------------------------------*/
53 /* --- @reffd_init@ --- *
55 * Arguments: @int fd@ = file descriptor
57 * Returns: Reference-counted file descriptor object.
59 * Use: Creates a refcounted file descriptor.
62 extern reffd *reffd_init(int /*fd*/);
64 /* --- @reffd_handler@ --- *
66 * Arguments: @reffd *r@ = pointer to reference counted filehandle
67 * @void (*proc)(void *p)@ = procedure to call
72 * Use: Sets the reference counted file descriptor to call @proc@
73 * when it is no longer required.
76 extern void reffd_handler(reffd */*r*/, void (*/*proc*/)(void */*p*/),
79 /* --- @reffd_inc@ --- *
81 * Arguments: @reffd *r@ = pointer to reference counted filehandle
85 * Use: Increments the reference count for a file descriptor.
88 #define REFFD_INC(r) do { (r)->ref++; } while (0)
90 extern void reffd_inc(reffd */*r*/);
92 /* --- @reffd_dec@ --- *
94 * Arguments: @reffd *r@ = pointer to reference counted filehandle
98 * Use: Decrements the reference count for a file descriptor.
101 #define REFFD_DEC(r) do { \
104 if (_r->ref == 0) { \
112 extern void reffd_dec(reffd */*r*/);
114 /*----- That's all, folks -------------------------------------------------*/