3 * Standard routines for forwarding sources
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the `fwd' port forwarder.
12 * `fwd' 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 * `fwd' 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 `fwd'; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Static variables --------------------------------------------------*/
31 static source *sources = 0;
33 /*----- Main code ---------------------------------------------------------*/
35 /* --- @source_add@ --- *
37 * Arguments: @source *s@ = pointer to a source
41 * Use: Adds a source to the master list. Only do this for passive
42 * sources (e.g., listening sockets), not active sources (e.g.,
43 * executable programs).
46 void source_add(source *s)
48 assert(s->ops->shutdown);
49 assert(!(s->f&SF_ACTIVE));
59 /* --- @source_remove@ --- *
61 * Arguments: @source *s@ = pointer to a source
65 * Use: Removes a source from the master list.
68 void source_remove(source *s)
70 assert(s->f&SF_ACTIVE);
72 s->next->prev = s->prev;
74 s->prev->next = s->next;
81 /* --- @source_inc@ --- *
83 * Arguments: @source *s@ = pointer to a source
87 * Use: Increments a source's refcount.
90 void source_inc(source *s) { s->ref++; }
92 /* --- @source_dec@ --- *
94 * Arguments: @source *s@ = pointer to a source
98 * Use: Decrements a source's refcount, destroying it if necessary.
101 void source_dec(source *s)
106 if (s->f&SF_ACTIVE) s->ops->shutdown(s);
111 /* --- @source_killall@ --- *
117 * Use: Frees all sources.
120 void source_killall(void)
126 ss->ops->shutdown(ss);
131 /*----- That's all, folks -------------------------------------------------*/