annotate src/io/rx_layer.c @ 0:d39e1d0d75b6

initial add
author paulo@hit-nxdomain.opendns.com
date Sat, 20 Feb 2010 21:18:28 -0800
parents
children
rev   line source
paulo@0 1 /*
paulo@0 2 * $Id: rx_layer.c,v 1.4 2004/02/01 08:17:12 hipnod Exp $
paulo@0 3 *
paulo@0 4 * Copyright (C) 2003 giFT project (gift.sourceforge.net)
paulo@0 5 *
paulo@0 6 * This program is free software; you can redistribute it and/or modify it
paulo@0 7 * under the terms of the GNU General Public License as published by the
paulo@0 8 * Free Software Foundation; either version 2, or (at your option) any
paulo@0 9 * later version.
paulo@0 10 *
paulo@0 11 * This program is distributed in the hope that it will be useful, but
paulo@0 12 * WITHOUT ANY WARRANTY; without even the implied warranty of
paulo@0 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
paulo@0 14 * General Public License for more details.
paulo@0 15 */
paulo@0 16
paulo@0 17 #include "gt_gnutella.h"
paulo@0 18
paulo@0 19 #include "rx_layer.h"
paulo@0 20
paulo@0 21 /*****************************************************************************/
paulo@0 22
paulo@0 23 void gt_rx_layer_disable (struct rx_layer *rx)
paulo@0 24 {
paulo@0 25 if (!rx)
paulo@0 26 return;
paulo@0 27
paulo@0 28 rx->enabled = FALSE;
paulo@0 29 rx->ops->disable (rx);
paulo@0 30 }
paulo@0 31
paulo@0 32 void gt_rx_layer_enable (struct rx_layer *rx)
paulo@0 33 {
paulo@0 34 if (!rx)
paulo@0 35 return;
paulo@0 36
paulo@0 37 rx->enabled = TRUE;
paulo@0 38 rx->ops->enable (rx);
paulo@0 39 }
paulo@0 40
paulo@0 41 void gt_rx_layer_recv (struct rx_layer *rx, struct io_buf *io_buf)
paulo@0 42 {
paulo@0 43 struct rx_layer *upper;
paulo@0 44
paulo@0 45 /* let the stack know we've started to receive some data */
paulo@0 46 gt_rx_stack_recv_start (rx->stack);
paulo@0 47
paulo@0 48 upper = rx->upper;
paulo@0 49 assert (rx->upper != NULL);
paulo@0 50
paulo@0 51 upper->ops->recv (upper, io_buf);
paulo@0 52
paulo@0 53 /*
paulo@0 54 * Let the stack know we're done. Currently, this will free the stack if
paulo@0 55 * rx_stack_abort() was called while we were receiving data.
paulo@0 56 *
paulo@0 57 * (Also note, the stack itself doesn't actually call free, but calls
paulo@0 58 * to the higher level callback's cleanup function, that calls
paulo@0 59 * gt_rx_stack_free().
paulo@0 60 */
paulo@0 61 gt_rx_stack_recv_end (rx->stack);
paulo@0 62 }
paulo@0 63
paulo@0 64 /*****************************************************************************/
paulo@0 65
paulo@0 66 struct rx_layer *gt_rx_layer_new (GtRxStack *stack, const char *name,
paulo@0 67 struct rx_layer_ops *ops, void *udata)
paulo@0 68 {
paulo@0 69 struct rx_layer *rx;
paulo@0 70
paulo@0 71 if (!(rx = NEW (struct rx_layer)))
paulo@0 72 return NULL;
paulo@0 73
paulo@0 74 rx->name = name;
paulo@0 75 rx->ops = ops; /* should we memdup this? */
paulo@0 76 rx->udata = udata;
paulo@0 77 rx->stack = stack;
paulo@0 78
paulo@0 79 /*
paulo@0 80 * Call the child initialization function.
paulo@0 81 */
paulo@0 82 if (!ops->init (rx, udata))
paulo@0 83 {
paulo@0 84 free (rx);
paulo@0 85 return NULL;
paulo@0 86 }
paulo@0 87
paulo@0 88 return rx;
paulo@0 89 }
paulo@0 90
paulo@0 91 void gt_rx_layer_free (struct rx_layer *rx)
paulo@0 92 {
paulo@0 93 if (!rx)
paulo@0 94 return;
paulo@0 95
paulo@0 96 /* tell the layer to free its data */
paulo@0 97 rx->ops->destroy (rx);
paulo@0 98
paulo@0 99 /* ops structues are global */
paulo@0 100 #if 0
paulo@0 101 free (rx->ops);
paulo@0 102 #endif
paulo@0 103
paulo@0 104 /* we free the layer itself here, at the top */
paulo@0 105 FREE (rx);
paulo@0 106 }