Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

mq.c File Reference


Detailed Description

Message queues, common code between TCP and UDP sending stacks.

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "nodes.h"
#include "mq.h"
#include "pmsg.h"
#include "gmsg.h"
#include "gnet_stats.h"
#include "lib/cq.h"
#include "lib/glib-missing.h"
#include "lib/walloc.h"
#include "if/gnet_property_priv.h"
#include "lib/override.h"

Defines

#define MQ_PUTQ(o, m)   ((o)->ops->putq((o), (m)))

Functions

void qlink_free (mqueue_t *q)
 Free the `qlink' sorted array of queued items.
void mq_update_flowc (mqueue_t *q)
 Update flow-control indication for queue.
gboolean make_room_header (mqueue_t *q, gchar *header, guint prio, gint needed, gint *offset)
 Same as make_room(), but we are not given a "pmsg_t" as a comparison point but a Gnutella header and a message priority explicitly.
void mq_swift_timer (cqueue_t *cq, gpointer obj)
 Callout queue callback: periodic "swift" mode timer.
gboolean mq_is_flow_controlled (const struct mqueue *q)
gboolean mq_is_swift_controlled (const struct mqueue *q)
gint mq_maxsize (const struct mqueue *q)
gint mq_size (const struct mqueue *q)
gint mq_lowat (const struct mqueue *q)
gint mq_hiwat (const struct mqueue *q)
gint mq_count (const struct mqueue *q)
gint mq_pending (const struct mqueue *q)
bio_sourcemq_bio (const struct mqueue *q)
gnutella_nodemq_node (const struct mqueue *q)
const gchar * mq_info (const mqueue_t *q)
 Compute readable queue information.
void mq_add_linkable (mqueue_t *q, GList *l)
 Add linkable into queue.
void mq_remove_linkable (mqueue_t *q, GList *l)
 Remove linkable from queue.
void mq_check_track (mqueue_t *q, gint offset, const gchar *where, gint line)
 Check queue's sanity.
void mq_free (mqueue_t *q)
 Free queue and all enqueued messages.
GList * mq_rmlink_prev (mqueue_t *q, GList *l, gint size)
 Remove link from message queue and return the previous item.
void mq_swift_checkpoint (mqueue_t *q, gboolean initial)
 A "swift" checkpoint was reached.
void mq_enter_swift (cqueue_t *unused_cq, gpointer obj)
 Callout queue callback invoked when the queue must enter "swift" mode.
void mq_enter_flowc (mqueue_t *q)
 Called when the message queue first enters flow-control.
void mq_leave_flowc (mqueue_t *q)
 Leaving flow-control state.
void mq_clear (mqueue_t *q)
 Remove all unsent messages from the queue.
void mq_discard (mqueue_t *q)
 Forbid further writes to the queue.
void mq_shutdown (mqueue_t *q)
 Disable all further writes from the queue.
gint qlink_cmp (const void *a, const void *b)
 Compare two pointers to links based on their relative priorities, then based on their held Gnutella messages.
void qlink_create (mqueue_t *q)
 Create the `qlink' sorted array of queued items.
void qlink_insert_before (mqueue_t *q, gint hint, GList *l)
 Insert linkable `l' within the sorted qlink array of linkables for the queue, before the position indicated by `hint'.
void qlink_insert (mqueue_t *q, GList *l)
 Insert linkable `l' within the sorted qlink array of linkables.
void qlink_remove (mqueue_t *q, GList *l)
 Remove the entry in the `qlink' linkable array, allowing compaction when there are too many holes.
gboolean make_room (mqueue_t *q, pmsg_t *mb, gint needed, gint *offset)
 Remove from the queue enough messages that are less prioritary than the current one, so as to make sure we can enqueue it.
void mq_puthere (mqueue_t *q, pmsg_t *mb, gint msize)
 Put message in this queue.
void mq_putq (mqueue_t *q, pmsg_t *mb)
 Enqueue message, which becomes owned by the queue.
const struct mq_copsmq_get_cops (void)
 Get common operations.

Variables

GHashTable * qown = NULL
const struct mq_cops mq_cops


Define Documentation

#define MQ_PUTQ o,
 )     ((o)->ops->putq((o), (m)))
 


Function Documentation

gboolean make_room mqueue_t q,
pmsg_t mb,
gint  needed,
gint *  offset
[static]
 

Remove from the queue enough messages that are less prioritary than the current one, so as to make sure we can enqueue it.

If `offset' is not null, it may be set with the offset within qlink where the message immediately more prioritary than `mb' can be found. It is up to the caller to initialize it with -1 and check whether it has been set.

Returns:
TRUE if we were able to make enough room.

gboolean make_room_header mqueue_t q,
gchar *  header,
guint  prio,
gint  needed,
gint *  offset
[static]
 

Same as make_room(), but we are not given a "pmsg_t" as a comparison point but a Gnutella header and a message priority explicitly.

void mq_add_linkable mqueue_t q,
GList *  l
[static]
 

Add linkable into queue.

struct bio_source* mq_bio const struct mqueue q  ) 
 

void mq_check_track mqueue_t q,
gint  offset,
const gchar *  where,
gint  line
 

Check queue's sanity.

void mq_clear mqueue_t q  ) 
 

Remove all unsent messages from the queue.

gint mq_count const struct mqueue q  ) 
 

void mq_discard mqueue_t q  ) 
 

Forbid further writes to the queue.

void mq_enter_flowc mqueue_t q  )  [static]
 

Called when the message queue first enters flow-control.

void mq_enter_swift cqueue_t unused_cq,
gpointer  obj
[static]
 

Callout queue callback invoked when the queue must enter "swift" mode.

void mq_free mqueue_t q  ) 
 

Free queue and all enqueued messages.

Since the message queue is the top of the network TX stack, calling mq_free() recursively requests freeing to lower layers.

const struct mq_cops* mq_get_cops void   ) 
 

Get common operations.

gint mq_hiwat const struct mqueue q  ) 
 

const gchar* mq_info const mqueue_t q  ) 
 

Compute readable queue information.

gboolean mq_is_flow_controlled const struct mqueue q  ) 
 

gboolean mq_is_swift_controlled const struct mqueue q  ) 
 

void mq_leave_flowc mqueue_t q  )  [static]
 

Leaving flow-control state.

gint mq_lowat const struct mqueue q  ) 
 

gint mq_maxsize const struct mqueue q  ) 
 

struct gnutella_node* mq_node const struct mqueue q  ) 
 

gint mq_pending const struct mqueue q  ) 
 

void mq_puthere mqueue_t q,
pmsg_t mb,
gint  msize
[static]
 

Put message in this queue.

void mq_putq mqueue_t q,
pmsg_t mb
 

Enqueue message, which becomes owned by the queue.

void mq_remove_linkable mqueue_t q,
GList *  l
[static]
 

Remove linkable from queue.

GList* mq_rmlink_prev mqueue_t q,
GList *  l,
gint  size
[static]
 

Remove link from message queue and return the previous item.

The `size' parameter refers to the size of the removed message.

The underlying message is freed and the size information on the queue is updated, but not the flow-control information.

void mq_shutdown mqueue_t q  ) 
 

Disable all further writes from the queue.

gint mq_size const struct mqueue q  ) 
 

void mq_swift_checkpoint mqueue_t q,
gboolean  initial
[static]
 

A "swift" checkpoint was reached.

void mq_swift_timer cqueue_t unused_cq,
gpointer  obj
[static]
 

Callout queue callback: periodic "swift" mode timer.

void mq_update_flowc mqueue_t q  )  [static]
 

Update flow-control indication for queue.

Invoke node "callbacks" when crossing a watermark boundary.

We define three levels: no flow-control, in warn zone, in flow-control.

gint qlink_cmp const void *  a,
const void *  b
[static]
 

Compare two pointers to links based on their relative priorities, then based on their held Gnutella messages.

-- qsort() callback

void qlink_create mqueue_t q  )  [static]
 

Create the `qlink' sorted array of queued items.

void qlink_free mqueue_t q  )  [static]
 

Free the `qlink' sorted array of queued items.

void qlink_insert mqueue_t q,
GList *  l
[static]
 

Insert linkable `l' within the sorted qlink array of linkables.

void qlink_insert_before mqueue_t q,
gint  hint,
GList *  l
[static]
 

Insert linkable `l' within the sorted qlink array of linkables for the queue, before the position indicated by `hint'.

void qlink_remove mqueue_t q,
GList *  l
[static]
 

Remove the entry in the `qlink' linkable array, allowing compaction when there are too many holes.

Parameters:
q the message queue
l the linkable to remove from the qlink indexer


Variable Documentation

const struct mq_cops mq_cops [static]
 

Initial value:

 {
    mq_puthere,             
    qlink_remove,           
    mq_rmlink_prev,         
    mq_update_flowc,        
}

GHashTable* qown = NULL [static]
 


Generated on Sat Jun 30 17:53:28 2007 for gtk-gnutella by  doxygen 1.3.9.1