00001 /* 00002 * $Id: mq.h,v 1.8 2005/08/02 10:29:50 rmanfredi Exp $ 00003 * 00004 * Copyright (c) 2002-2003, Raphael Manfredi 00005 * 00006 *---------------------------------------------------------------------- 00007 * This file is part of gtk-gnutella. 00008 * 00009 * gtk-gnutella is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * gtk-gnutella is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with gtk-gnutella; if not, write to the Free Software 00021 * Foundation, Inc.: 00022 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 *---------------------------------------------------------------------- 00024 */ 00025 00036 #ifndef _core_mq_h_ 00037 #define _core_mq_h_ 00038 00039 #include <glib.h> 00040 00041 #include "gnutella.h" 00042 #include "pmsg.h" 00043 #include "tx.h" 00044 00045 typedef struct mqueue mqueue_t; 00046 00051 struct mq_ops { 00052 void (*putq)(mqueue_t *q, pmsg_t *mb); 00053 }; 00054 00055 struct mq_cops { 00056 void (*puthere)(mqueue_t *q, pmsg_t *mb, gint msize); 00057 void (*qlink_remove)(mqueue_t *q, GList *l); 00058 GList *(*rmlink_prev)(mqueue_t *q, GList *l, gint size); 00059 void (*update_flowc)(mqueue_t *q); 00060 }; 00061 00080 struct mqueue { 00081 struct gnutella_header header; 00082 struct gnutella_node *node; 00083 const struct mq_ops *ops; 00084 const struct mq_cops *cops; 00085 txdrv_t *tx_drv; 00086 GList *qhead; 00087 GList *qtail; 00088 GList **qlink; 00089 gpointer swift_ev; 00090 gint swift_elapsed; 00091 gint qlink_count; 00092 gint maxsize; 00093 gint count; 00094 gint hiwat; 00095 gint lowat; 00096 gint size; 00097 gint flags; 00098 gint last_written; 00099 gint flowc_written; 00100 gint last_size; 00101 }; 00102 00103 /* 00104 * Queue flags. 00105 */ 00106 00107 #define MQ_FLOWC 0x00000001 00108 #define MQ_DISCARD 0x00000002 00109 #define MQ_SWIFT 0x00000004 00110 #define MQ_WARNZONE 0x00000008 00112 #define mq_is_flow_controlled(q) ((q)->flags & MQ_FLOWC) 00113 #define mq_is_swift_controlled(q) ((q)->flags & MQ_SWIFT) 00114 #define mq_maxsize(q) ((q)->maxsize) 00115 #define mq_size(q) ((q)->size) 00116 #define mq_lowat(q) ((q)->lowat) 00117 #define mq_hiwat(q) ((q)->hiwat) 00118 #define mq_count(q) ((q)->count) 00119 #define mq_pending(q) ((q)->size + tx_pending((q)->tx_drv)) 00120 #define mq_bio(q) (tx_bio_source((q)->tx_drv)) 00121 #define mq_node(q) ((q)->node) 00122 00123 /* 00124 * Public interface 00125 */ 00126 00127 void mq_putq(mqueue_t *q, pmsg_t *mb); 00128 void mq_free(mqueue_t *q); 00129 void mq_clear(mqueue_t *q); 00130 void mq_discard(mqueue_t *q); 00131 void mq_shutdown(mqueue_t *q); 00132 void mq_fill_ops(struct mq_ops *ops); 00133 00134 const struct mq_cops *mq_get_cops(void); 00135 00136 #endif /* _core_mq_h_ */ 00137 00138 /* vi: set ts=4: */