X-Git-Url: https://git.distorted.org.uk/~mdw/fwd/blobdiff_plain/667fb920a9ace885b3ac2dc8277d104930bd2727..07d71f34ab3887b63c6ff2d635fce07368f90295:/reffd.c diff --git a/reffd.c b/reffd.c new file mode 100644 index 0000000..823b102 --- /dev/null +++ b/reffd.c @@ -0,0 +1,111 @@ +/* -*-c-*- + * + * $Id: reffd.c,v 1.1 1999/07/26 23:33:01 mdw Exp $ + * + * Reference counted file descriptors + * + * (c) 1999 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of the `fw' port forwarder. + * + * `fw' is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * `fw' is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with `fw'; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: reffd.c,v $ + * Revision 1.1 1999/07/26 23:33:01 mdw + * Infrastructure for the new design. + * + */ + +/*----- Header files ------------------------------------------------------*/ + +#include +#include +#include + +#include +#include + +#include + +#include "reffd.h" + +/*----- Main code ---------------------------------------------------------*/ + +/* --- @reffd_init@ --- * + * + * Arguments: @int fd@ = file descriptor + * + * Returns: Reference-counted file descriptor object. + * + * Use: Creates a refcounted file descriptor. + */ + +reffd *reffd_init(int fd) +{ + reffd *r = CREATE(reffd); + r->fd = fd; + r->ref = 1; + r->proc = 0; + r->p = 0; + return (r); +} + +/* --- @reffd_handler@ --- * + * + * Arguments: @reffd *r@ = pointer to reference counted filehandle + * @void (*proc)(void *p)@ = procedure to call + * @void *p@ + * + * Returns: --- + * + * Use: Sets the reference counted file descriptor to call @proc@ + * when it is no longer required. + */ + +void reffd_handler(reffd *r, void (*proc)(void *p), void *p) +{ + r->proc = proc; + r->p = p; +} + +/* --- @reffd_inc@ --- * + * + * Arguments: @reffd *r@ = pointer to reference counted filehandle + * + * Returns: --- + * + * Use: Increments the reference count for a file descriptor. + */ + +void reffd_inc(reffd *r) { REFFD_INC(r); } + +/* --- @reffd_dec@ --- * + * + * Arguments: @reffd *r@ = pointer to reference counted filehandle + * + * Returns: --- + * + * Use: Decrements the reference count for a file descriptor. + */ + +void reffd_dec(reffd *r) { REFFD_DEC(r); } + +/*----- That's all, folks -------------------------------------------------*/