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