diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/io/rx_layer.c	Sat Feb 20 21:18:28 2010 -0800
     1.3 @@ -0,0 +1,106 @@
     1.4 +/*
     1.5 + * $Id: rx_layer.c,v 1.4 2004/02/01 08:17:12 hipnod Exp $
     1.6 + *
     1.7 + * Copyright (C) 2003 giFT project (gift.sourceforge.net)
     1.8 + *
     1.9 + * This program is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License as published by the
    1.11 + * Free Software Foundation; either version 2, or (at your option) any
    1.12 + * later version.
    1.13 + *
    1.14 + * This program is distributed in the hope that it will be useful, but
    1.15 + * WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 + * General Public License for more details.
    1.18 + */
    1.19 +
    1.20 +#include "gt_gnutella.h"
    1.21 +
    1.22 +#include "rx_layer.h"
    1.23 +
    1.24 +/*****************************************************************************/
    1.25 +
    1.26 +void gt_rx_layer_disable (struct rx_layer *rx)
    1.27 +{
    1.28 +	if (!rx)
    1.29 +		return;
    1.30 +
    1.31 +	rx->enabled = FALSE;
    1.32 +	rx->ops->disable (rx);
    1.33 +}
    1.34 +
    1.35 +void gt_rx_layer_enable (struct rx_layer *rx)
    1.36 +{
    1.37 +	if (!rx)
    1.38 +		return;
    1.39 +
    1.40 +	rx->enabled = TRUE;
    1.41 +	rx->ops->enable (rx);
    1.42 +}
    1.43 +
    1.44 +void gt_rx_layer_recv (struct rx_layer *rx, struct io_buf *io_buf)
    1.45 +{
    1.46 +	struct rx_layer *upper;
    1.47 +
    1.48 +	/* let the stack know we've started to receive some data */
    1.49 +	gt_rx_stack_recv_start (rx->stack);
    1.50 +
    1.51 +	upper = rx->upper;
    1.52 +	assert (rx->upper != NULL);
    1.53 +
    1.54 +	upper->ops->recv (upper, io_buf);
    1.55 +
    1.56 +	/* 
    1.57 +	 * Let the stack know we're done. Currently, this will free the stack if
    1.58 +	 * rx_stack_abort() was called while we were receiving data.
    1.59 +	 *
    1.60 +	 * (Also note, the stack itself doesn't actually call free, but calls
    1.61 +	 * to the higher level callback's cleanup function, that calls 
    1.62 +	 * gt_rx_stack_free().
    1.63 +	 */
    1.64 +	gt_rx_stack_recv_end (rx->stack);
    1.65 +}
    1.66 +
    1.67 +/*****************************************************************************/
    1.68 +
    1.69 +struct rx_layer *gt_rx_layer_new (GtRxStack *stack, const char *name,
    1.70 +                               struct rx_layer_ops *ops, void *udata)
    1.71 +{
    1.72 +	struct rx_layer *rx;
    1.73 +
    1.74 +	if (!(rx = NEW (struct rx_layer)))
    1.75 +		return NULL;
    1.76 +
    1.77 +	rx->name  = name;
    1.78 +	rx->ops   = ops;    /* should we memdup this? */
    1.79 +	rx->udata = udata;
    1.80 +	rx->stack = stack;
    1.81 +
    1.82 +	/*
    1.83 +	 * Call the child initialization function.
    1.84 +	 */
    1.85 +	if (!ops->init (rx, udata))
    1.86 +	{
    1.87 +		free (rx);
    1.88 +		return NULL;
    1.89 +	}
    1.90 +
    1.91 +	return rx;
    1.92 +}
    1.93 +
    1.94 +void gt_rx_layer_free (struct rx_layer *rx)
    1.95 +{
    1.96 +	if (!rx)
    1.97 +		return;
    1.98 +
    1.99 +	/* tell the layer to free its data */
   1.100 +	rx->ops->destroy (rx);
   1.101 +
   1.102 +	/* ops structues are global */
   1.103 +#if 0
   1.104 +	free (rx->ops);
   1.105 +#endif
   1.106 +
   1.107 +	/* we free the layer itself here, at the top */
   1.108 +	FREE (rx);
   1.109 +}