paulo@0: /* paulo@0: * $Id: rx_layer.c,v 1.4 2004/02/01 08:17:12 hipnod Exp $ paulo@0: * paulo@0: * Copyright (C) 2003 giFT project (gift.sourceforge.net) paulo@0: * paulo@0: * This program is free software; you can redistribute it and/or modify it paulo@0: * under the terms of the GNU General Public License as published by the paulo@0: * Free Software Foundation; either version 2, or (at your option) any paulo@0: * later version. paulo@0: * paulo@0: * This program is distributed in the hope that it will be useful, but paulo@0: * WITHOUT ANY WARRANTY; without even the implied warranty of paulo@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU paulo@0: * General Public License for more details. paulo@0: */ paulo@0: paulo@0: #include "gt_gnutella.h" paulo@0: paulo@0: #include "rx_layer.h" paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: void gt_rx_layer_disable (struct rx_layer *rx) paulo@0: { paulo@0: if (!rx) paulo@0: return; paulo@0: paulo@0: rx->enabled = FALSE; paulo@0: rx->ops->disable (rx); paulo@0: } paulo@0: paulo@0: void gt_rx_layer_enable (struct rx_layer *rx) paulo@0: { paulo@0: if (!rx) paulo@0: return; paulo@0: paulo@0: rx->enabled = TRUE; paulo@0: rx->ops->enable (rx); paulo@0: } paulo@0: paulo@0: void gt_rx_layer_recv (struct rx_layer *rx, struct io_buf *io_buf) paulo@0: { paulo@0: struct rx_layer *upper; paulo@0: paulo@0: /* let the stack know we've started to receive some data */ paulo@0: gt_rx_stack_recv_start (rx->stack); paulo@0: paulo@0: upper = rx->upper; paulo@0: assert (rx->upper != NULL); paulo@0: paulo@0: upper->ops->recv (upper, io_buf); paulo@0: paulo@0: /* paulo@0: * Let the stack know we're done. Currently, this will free the stack if paulo@0: * rx_stack_abort() was called while we were receiving data. paulo@0: * paulo@0: * (Also note, the stack itself doesn't actually call free, but calls paulo@0: * to the higher level callback's cleanup function, that calls paulo@0: * gt_rx_stack_free(). paulo@0: */ paulo@0: gt_rx_stack_recv_end (rx->stack); paulo@0: } paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: struct rx_layer *gt_rx_layer_new (GtRxStack *stack, const char *name, paulo@0: struct rx_layer_ops *ops, void *udata) paulo@0: { paulo@0: struct rx_layer *rx; paulo@0: paulo@0: if (!(rx = NEW (struct rx_layer))) paulo@0: return NULL; paulo@0: paulo@0: rx->name = name; paulo@0: rx->ops = ops; /* should we memdup this? */ paulo@0: rx->udata = udata; paulo@0: rx->stack = stack; paulo@0: paulo@0: /* paulo@0: * Call the child initialization function. paulo@0: */ paulo@0: if (!ops->init (rx, udata)) paulo@0: { paulo@0: free (rx); paulo@0: return NULL; paulo@0: } paulo@0: paulo@0: return rx; paulo@0: } paulo@0: paulo@0: void gt_rx_layer_free (struct rx_layer *rx) paulo@0: { paulo@0: if (!rx) paulo@0: return; paulo@0: paulo@0: /* tell the layer to free its data */ paulo@0: rx->ops->destroy (rx); paulo@0: paulo@0: /* ops structues are global */ paulo@0: #if 0 paulo@0: free (rx->ops); paulo@0: #endif paulo@0: paulo@0: /* we free the layer itself here, at the top */ paulo@0: FREE (rx); paulo@0: }