2
* $Id: tx.c,v 1.9 2005/05/29 08:48:36 graaff Exp $
4
* Copyright (c) 2002-2003, Raphael Manfredi
6
*----------------------------------------------------------------------
7
* This file is part of gtk-gnutella.
9
* gtk-gnutella is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* gtk-gnutella is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with gtk-gnutella; if not, write to the Free Software
22
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
*----------------------------------------------------------------------
32
* This file is the "ancestor" class of all TX drivers, and therefore only
33
* implements general routines that are mostly common, as well as provides
34
* type-checked entry points for dynamically dispatched routines, such
37
* @author Raphael Manfredi
43
RCSID("$Id: tx.c,v 1.9 2005/05/29 08:48:36 graaff Exp $");
46
#include "lib/override.h" /* Must be the last header included */
49
* Dynamic dispatch of polymorphic routines.
52
#define TX_INIT(o,a) ((o)->ops->init((o), (a)))
53
#define TX_DESTROY(o) ((o)->ops->destroy((o)))
54
#define TX_WRITE(o,d,l) ((o)->ops->write((o), (d), (l)))
55
#define TX_WRITEV(o,i,c) ((o)->ops->writev((o), (i), (c)))
56
#define TX_SENDTO(o,t,d,l) ((o)->ops->sendto((o), (t), (d), (l)))
57
#define TX_ENABLE(o) ((o)->ops->enable((o)))
58
#define TX_DISABLE(o) ((o)->ops->disable((o)))
59
#define TX_PENDING(o) ((o)->ops->pending((o)))
60
#define TX_BIO_SOURCE(o) ((o)->ops->bio_source((o)))
61
#define TX_FLUSH(o) ((o)->ops->flush((o)))
64
* Create a new network driver, equipped with the `ops' operations and
65
* initialize its specific parameters by calling the init routine with `args'.
67
* @return NULL if there is an initialization problem.
70
tx_make(struct gnutella_node *n, const struct txdrv_ops *ops, gpointer args)
77
tx = g_malloc0(sizeof(*tx));
82
if (NULL == TX_INIT(tx, args)) /* Let the heir class initialize */
89
* Dispose of the driver resources.
101
* Write `len' bytes starting at `data'.
103
* @return the amount of bytes written, or -1 with errno set on error.
106
tx_write(txdrv_t *tx, gpointer data, size_t len)
108
return TX_WRITE(tx, data, len);
114
* @return amount of bytes written, or -1 on error with errno set.
117
tx_writev(txdrv_t *tx, struct iovec *iov, gint iovcnt)
119
return TX_WRITEV(tx, iov, iovcnt);
123
* Send buffer datagram to specified destination `to'.
125
* @return amount of bytes written, or -1 on error with errno set.
128
tx_sendto(txdrv_t *tx, gnet_host_t *to, gpointer data, size_t len)
130
return TX_SENDTO(tx, to, data, len);
134
* Register service routine from upper TX layer.
137
tx_srv_register(txdrv_t *tx, tx_service_t srv_fn, gpointer srv_arg)
142
tx->srv_routine = srv_fn;
143
tx->srv_arg = srv_arg;
147
* Record that upper layer wants its service routine enabled.
150
tx_srv_enable(txdrv_t *tx)
152
if (tx->flags & TX_SERVICE) /* Already enabled */
156
tx->flags |= TX_SERVICE;
160
* Record that upper layer wants its service routine disabled.
163
tx_srv_disable(txdrv_t *tx)
165
g_assert(tx->flags & TX_SERVICE);
168
tx->flags &= ~TX_SERVICE;
172
* @return amount of data pending in the whole stack.
175
tx_pending(txdrv_t *tx)
179
return TX_PENDING(tx);
183
* The I/O source of the lowest layer (link) that physically sends
187
tx_bio_source(txdrv_t *tx)
191
return TX_BIO_SOURCE(tx);
195
* Request that data be sent immediately.
198
tx_flush(txdrv_t *tx)
206
* The write() operation is forbidden.
209
tx_no_write(txdrv_t *unused_tx, gpointer unused_data, size_t unused_len)
214
g_error("no write() operation allowed");
220
* The writev() operation is forbidden.
223
tx_no_writev(txdrv_t *unused_tx, struct iovec *unused_iov, gint unused_iovcnt)
227
(void) unused_iovcnt;
228
g_error("no writev() operation allowed");
234
* The sendto() operation is forbidden.
237
tx_no_sendto(txdrv_t *unused_tx, gnet_host_t *unused_to,
238
gpointer unused_data, size_t unused_len)
244
g_error("no sendto() operation allowed");
249
/* vi: set ts=4 sw=4 cindent: */