5e03f1b4ab083ff8d957b912c268f7c7f66c59a8
3 * Reference counted file descriptors
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the `fw' port forwarder.
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.
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.
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.
34 /*----- Header files ------------------------------------------------------*/
40 /*----- Data structures ---------------------------------------------------*/
42 typedef struct reffd
{
45 void (*proc
)(void */
*p*/
);
49 /*----- Functions provided ------------------------------------------------*/
51 /* --- @reffd_init@ --- *
53 * Arguments: @int fd@ = file descriptor
55 * Returns: Reference-counted file descriptor object.
57 * Use: Creates a refcounted file descriptor.
60 extern reffd
*reffd_init(int /*fd*/);
62 /* --- @reffd_handler@ --- *
64 * Arguments: @reffd *r@ = pointer to reference counted filehandle
65 * @void (*proc)(void *p)@ = procedure to call
70 * Use: Sets the reference counted file descriptor to call @proc@
71 * when it is no longer required.
74 extern void reffd_handler(reffd */
*r*/
, void (*/
*proc*/
)(void */
*p*/
),
77 /* --- @reffd_inc@ --- *
79 * Arguments: @reffd *r@ = pointer to reference counted filehandle
83 * Use: Increments the reference count for a file descriptor.
86 #define REFFD_INC(r) do { (r)->ref++; } while (0)
88 extern void reffd_inc(reffd */
*r*/
);
90 /* --- @reffd_dec@ --- *
92 * Arguments: @reffd *r@ = pointer to reference counted filehandle
96 * Use: Decrements the reference count for a file descriptor.
99 #define REFFD_DEC(r) do { \
102 if (_r->ref == 0) { \
110 extern void reffd_dec(reffd */
*r*/
);
112 /*----- That's all, folks -------------------------------------------------*/