diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/io/tx_layer.h	Sat Feb 20 21:18:28 2010 -0800
     1.3 @@ -0,0 +1,96 @@
     1.4 +/*
     1.5 + * $Id: tx_layer.h,v 1.5 2004/01/31 13:33:17 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 +#ifndef GIFT_GT_TX_LAYER_H_
    1.21 +#define GIFT_GT_TX_LAYER_H_
    1.22 +
    1.23 +/*****************************************************************************/
    1.24 +
    1.25 +struct tx_layer_ops;
    1.26 +struct tx_layer;
    1.27 +
    1.28 +struct io_buf;
    1.29 +struct gt_tx_stack;
    1.30 +
    1.31 +/*
    1.32 + * Return codes from the TX stack functions that lets the caller know
    1.33 + * what processing occured.
    1.34 + */
    1.35 +typedef enum tx_status
    1.36 +{
    1.37 +	TX_OK,
    1.38 +	TX_FULL,             /* lower layer became saturated */
    1.39 +	TX_EMPTY,            /* no waiting data */
    1.40 +	TX_PARTIAL,          /* buffer partially read */
    1.41 +	TX_ERROR,            /* general error */
    1.42 +} tx_status_t;
    1.43 +
    1.44 +struct tx_layer_ops
    1.45 +{
    1.46 +	BOOL        (*init)       (struct tx_layer *tx);
    1.47 +	void        (*destroy)    (struct tx_layer *tx);
    1.48 +
    1.49 +	/*
    1.50 +	 * If the layer is capable of consuming data (for example
    1.51 +	 * by sending it out on a connection), begin or stop flushing by obeying
    1.52 +	 * the 'stop' argument.  Only the bottommost layer in a stack
    1.53 +	 * should implement this.
    1.54 +	 */
    1.55 +	void        (*toggle)     (struct tx_layer *tx, BOOL stop);
    1.56 +
    1.57 +	/* upper layer has sent us a buffer */
    1.58 +	tx_status_t (*queue)      (struct tx_layer *tx, struct io_buf *io_buf);
    1.59 +
    1.60 +	/* lower layer wants us to send a buffer */
    1.61 +	tx_status_t (*ready)      (struct tx_layer *tx);   /* lower layer wants data */
    1.62 +
    1.63 +	/* enable/disable this layer completely */
    1.64 +	void        (*enable)     (struct tx_layer *tx);
    1.65 +	void        (*disable)    (struct tx_layer *tx);
    1.66 +};
    1.67 +
    1.68 +struct tx_layer
    1.69 +{
    1.70 +	void                *udata;
    1.71 +	struct tx_layer_ops *ops;
    1.72 +
    1.73 +	struct tx_layer     *upper;
    1.74 +	struct tx_layer     *lower;
    1.75 +
    1.76 +	/* leftovers from previous queue operations */
    1.77 +	struct io_buf       *partial_buf;
    1.78 +
    1.79 +	struct gt_tx_stack  *stack;
    1.80 +	const char          *name;
    1.81 +};
    1.82 +
    1.83 +/*****************************************************************************/
    1.84 +
    1.85 +struct tx_layer *gt_tx_layer_new      (struct gt_tx_stack *stack,
    1.86 +                                       const char *name,
    1.87 +                                       struct tx_layer_ops *ops);
    1.88 +void             gt_tx_layer_free     (struct tx_layer *layer);
    1.89 +
    1.90 +void             gt_tx_layer_enable   (struct tx_layer *layer);
    1.91 +void             gt_tx_layer_disable  (struct tx_layer *layer);
    1.92 +
    1.93 +tx_status_t      gt_tx_layer_queue    (struct tx_layer *layer,
    1.94 +                                       struct io_buf *buf);
    1.95 +tx_status_t      gt_tx_layer_ready    (struct tx_layer *layer);
    1.96 +
    1.97 +/*****************************************************************************/
    1.98 +
    1.99 +#endif /* GIFT_GT_TX_LAYER_H_ */