Use new mLib selbuf features.
[fwd] / reffd.c
CommitLineData
07d71f34 1/* -*-c-*-
2 *
3 * $Id: reffd.c,v 1.1 1999/07/26 23:33:01 mdw Exp $
4 *
5 * Reference counted file descriptors
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: reffd.c,v $
32 * Revision 1.1 1999/07/26 23:33:01 mdw
33 * Infrastructure for the new design.
34 *
35 */
36
37/*----- Header files ------------------------------------------------------*/
38
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42
43#include <sys/types.h>
44#include <unistd.h>
45
46#include <mLib/sub.h>
47
48#include "reffd.h"
49
50/*----- Main code ---------------------------------------------------------*/
51
52/* --- @reffd_init@ --- *
53 *
54 * Arguments: @int fd@ = file descriptor
55 *
56 * Returns: Reference-counted file descriptor object.
57 *
58 * Use: Creates a refcounted file descriptor.
59 */
60
61reffd *reffd_init(int fd)
62{
63 reffd *r = CREATE(reffd);
64 r->fd = fd;
65 r->ref = 1;
66 r->proc = 0;
67 r->p = 0;
68 return (r);
69}
70
71/* --- @reffd_handler@ --- *
72 *
73 * Arguments: @reffd *r@ = pointer to reference counted filehandle
74 * @void (*proc)(void *p)@ = procedure to call
75 * @void *p@
76 *
77 * Returns: ---
78 *
79 * Use: Sets the reference counted file descriptor to call @proc@
80 * when it is no longer required.
81 */
82
83void reffd_handler(reffd *r, void (*proc)(void *p), void *p)
84{
85 r->proc = proc;
86 r->p = p;
87}
88
89/* --- @reffd_inc@ --- *
90 *
91 * Arguments: @reffd *r@ = pointer to reference counted filehandle
92 *
93 * Returns: ---
94 *
95 * Use: Increments the reference count for a file descriptor.
96 */
97
98void reffd_inc(reffd *r) { REFFD_INC(r); }
99
100/* --- @reffd_dec@ --- *
101 *
102 * Arguments: @reffd *r@ = pointer to reference counted filehandle
103 *
104 * Returns: ---
105 *
106 * Use: Decrements the reference count for a file descriptor.
107 */
108
109void reffd_dec(reffd *r) { REFFD_DEC(r); }
110
111/*----- That's all, folks -------------------------------------------------*/