comparison src/io/tx_layer.h @ 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:ebb05c55217a
1 /*
2 * $Id: tx_layer.h,v 1.5 2004/01/31 13:33:17 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 #ifndef GIFT_GT_TX_LAYER_H_
18 #define GIFT_GT_TX_LAYER_H_
19
20 /*****************************************************************************/
21
22 struct tx_layer_ops;
23 struct tx_layer;
24
25 struct io_buf;
26 struct gt_tx_stack;
27
28 /*
29 * Return codes from the TX stack functions that lets the caller know
30 * what processing occured.
31 */
32 typedef enum tx_status
33 {
34 TX_OK,
35 TX_FULL, /* lower layer became saturated */
36 TX_EMPTY, /* no waiting data */
37 TX_PARTIAL, /* buffer partially read */
38 TX_ERROR, /* general error */
39 } tx_status_t;
40
41 struct tx_layer_ops
42 {
43 BOOL (*init) (struct tx_layer *tx);
44 void (*destroy) (struct tx_layer *tx);
45
46 /*
47 * If the layer is capable of consuming data (for example
48 * by sending it out on a connection), begin or stop flushing by obeying
49 * the 'stop' argument. Only the bottommost layer in a stack
50 * should implement this.
51 */
52 void (*toggle) (struct tx_layer *tx, BOOL stop);
53
54 /* upper layer has sent us a buffer */
55 tx_status_t (*queue) (struct tx_layer *tx, struct io_buf *io_buf);
56
57 /* lower layer wants us to send a buffer */
58 tx_status_t (*ready) (struct tx_layer *tx); /* lower layer wants data */
59
60 /* enable/disable this layer completely */
61 void (*enable) (struct tx_layer *tx);
62 void (*disable) (struct tx_layer *tx);
63 };
64
65 struct tx_layer
66 {
67 void *udata;
68 struct tx_layer_ops *ops;
69
70 struct tx_layer *upper;
71 struct tx_layer *lower;
72
73 /* leftovers from previous queue operations */
74 struct io_buf *partial_buf;
75
76 struct gt_tx_stack *stack;
77 const char *name;
78 };
79
80 /*****************************************************************************/
81
82 struct tx_layer *gt_tx_layer_new (struct gt_tx_stack *stack,
83 const char *name,
84 struct tx_layer_ops *ops);
85 void gt_tx_layer_free (struct tx_layer *layer);
86
87 void gt_tx_layer_enable (struct tx_layer *layer);
88 void gt_tx_layer_disable (struct tx_layer *layer);
89
90 tx_status_t gt_tx_layer_queue (struct tx_layer *layer,
91 struct io_buf *buf);
92 tx_status_t gt_tx_layer_ready (struct tx_layer *layer);
93
94 /*****************************************************************************/
95
96 #endif /* GIFT_GT_TX_LAYER_H_ */