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

pmsg.c File Reference


Detailed Description

PDU Messages.

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "pmsg.h"
#include "lib/zalloc.h"
#include "lib/walloc.h"
#include "lib/override.h"

Data Structures

struct  pmsg_ext
 An extended message block. More...


Defines

#define implies(a, b)   (!(a) || (b))
#define valid_ptr(a)   (((gulong) (a)) > 100L)
#define EMBEDDED_OFFSET   G_STRUCT_OFFSET(pdata_t, d_embedded)

Typedefs

typedef pmsg_ext pmsg_ext_t
 An extended message block.


Functions

 RCSID ("$Id:pmsg.c, v 1.9 2005/06/25 01:37:40 daichik Exp $")
void pmsg_init (void)
 Allocate internal variables.

void pmsg_close (void)
 Free internal variables.

int pmsg_size (pmsg_t *mb)
 Compute message's size.

pmsg_tpmsg_fill (pmsg_t *mb, pdata_t *db, gint prio, gconstpointer buf, gint len)
 Fill newly created message block.

pmsg_tpmsg_new (gint prio, gconstpointer buf, gint len)
 Create new message from user provided data, which are copied into the allocated data block.

pmsg_tpmsg_new_extend (gint prio, gconstpointer buf, gint len, pmsg_free_t free_cb, gpointer arg)
 Like pmsg_new() but returns an extended form with a free routine callback.

pmsg_tpmsg_alloc (gint prio, pdata_t *db, gint roff, gint woff)
 Allocate new message using existing data block `db'.

pmsg_tpmsg_clone_extend (pmsg_t *mb, pmsg_free_t free_cb, gpointer arg)
 Extended cloning of message, adds a free routine callback.

pmsg_free_t pmsg_replace_ext (pmsg_t *mb, pmsg_free_t nfree, gpointer narg, gpointer *oarg)
 Replace free routine from an extended message block.

gpointer pmsg_get_metadata (pmsg_t *mb)
 Get the "meta data" from an extended message block (the argument passed to the embedded free routine).

pmsg_check_t pmsg_set_check (pmsg_t *mb, pmsg_check_t check)
 Set the pre-send checking routine for the buffer.

pmsg_tpmsg_clone_ext (pmsg_ext_t *mb)
 Shallow cloning of extended message, result is referencing the same data.

pmsg_tpmsg_clone (pmsg_t *mb)
 Shallow cloning of message, result is referencing the same data.

void pmsg_free (pmsg_t *mb)
 Free all message blocks, and decrease ref count on all data buffers.

gint pmsg_write (pmsg_t *mb, gconstpointer data, gint len)
 Write data at the end of the message.

gint pmsg_read (pmsg_t *mb, gpointer data, gint len)
 Read data from the message, returning the amount of bytes transferred.

pdata_tpdata_new (int len)
 Allocate a new data block of given size.

pdata_tpdata_allocb (void *buf, gint len, pdata_free_t freecb, gpointer freearg)
 Create an embedded data buffer out of existing arena.

pdata_tpdata_allocb_ext (void *buf, gint len, pdata_free_t freecb, gpointer freearg)
 Create an external (arena not embedded) data buffer out of existing arena.

void pdata_free_nop (gpointer unused_p, gpointer unused_arg)
 This free routine can be used when there is nothing to be freed for the buffer, probably because it was made out of a static buffer.

void pdata_free (pdata_t *db)
 Free data block when its reference count has reached 0.

void pdata_unref (pdata_t *db)
 Decrease reference count on buffer, and free it when it reaches 0.


Variables

zone_tmb_zone = NULL


Define Documentation

#define EMBEDDED_OFFSET   G_STRUCT_OFFSET(pdata_t, d_embedded)
 

#define implies a,
 )     (!(a) || (b))
 

#define valid_ptr  )     (((gulong) (a)) > 100L)
 


Typedef Documentation

typedef struct pmsg_ext pmsg_ext_t
 

An extended message block.

Relies on C's structural equivalence for the first 4 fields. An extended message block can be identified by its `m_prio' field having the PMSG_PF_EXT flag set.


Function Documentation

pdata_t* pdata_allocb void *  buf,
gint  len,
pdata_free_t  freecb,
gpointer  freearg
 

Create an embedded data buffer out of existing arena.

The optional `freecb' structure supplies the free routine callback to be used to free the arena, with freearg as additional argument.

pdata_t* pdata_allocb_ext void *  buf,
gint  len,
pdata_free_t  freecb,
gpointer  freearg
 

Create an external (arena not embedded) data buffer out of existing arena.

The optional `freecb' structure supplies the free routine callback to be used to free the arena, with freearg as additional argument.

void pdata_free pdata_t db  )  [static]
 

Free data block when its reference count has reached 0.

void pdata_free_nop gpointer  unused_p,
gpointer  unused_arg
 

This free routine can be used when there is nothing to be freed for the buffer, probably because it was made out of a static buffer.

pdata_t* pdata_new int  len  ) 
 

Allocate a new data block of given size.

The block header is at the start of the allocated block.

void pdata_unref pdata_t db  ) 
 

Decrease reference count on buffer, and free it when it reaches 0.

pmsg_t* pmsg_alloc gint  prio,
pdata_t db,
gint  roff,
gint  woff
 

Allocate new message using existing data block `db'.

The `roff' and `woff' are used to delimit the start and the end (first unwritten byte) of the message within the data buffer.

Returns:
new message.

pmsg_t* pmsg_clone pmsg_t mb  ) 
 

Shallow cloning of message, result is referencing the same data.

pmsg_t* pmsg_clone_ext pmsg_ext_t mb  )  [static]
 

Shallow cloning of extended message, result is referencing the same data.

pmsg_t* pmsg_clone_extend pmsg_t mb,
pmsg_free_t  free_cb,
gpointer  arg
 

Extended cloning of message, adds a free routine callback.

void pmsg_close void   ) 
 

Free internal variables.

pmsg_t* pmsg_fill pmsg_t mb,
pdata_t db,
gint  prio,
gconstpointer  buf,
gint  len
[static]
 

Fill newly created message block.

Returns:
the message block given as argument.

void pmsg_free pmsg_t mb  ) 
 

Free all message blocks, and decrease ref count on all data buffers.

gpointer pmsg_get_metadata pmsg_t mb  ) 
 

Get the "meta data" from an extended message block (the argument passed to the embedded free routine).

void pmsg_init void   ) 
 

Allocate internal variables.

pmsg_t* pmsg_new gint  prio,
gconstpointer  buf,
gint  len
 

Create new message from user provided data, which are copied into the allocated data block.

If no user buffer is provided, an empty message is created and the length is used to size the data block.

Returns:
a message made of one message block referencing one new data block.

pmsg_t* pmsg_new_extend gint  prio,
gconstpointer  buf,
gint  len,
pmsg_free_t  free_cb,
gpointer  arg
 

Like pmsg_new() but returns an extended form with a free routine callback.

gint pmsg_read pmsg_t mb,
gpointer  data,
gint  len
 

Read data from the message, returning the amount of bytes transferred.

pmsg_free_t pmsg_replace_ext pmsg_t mb,
pmsg_free_t  nfree,
gpointer  narg,
gpointer *  oarg
 

Replace free routine from an extended message block.

The original free routine and its argument are returned.

This is used when wrapping an existing extended message and its metadata in another extension structure.

Parameters:
mb the extended message block
nfree the new free routine (NULL to cancel)
narg the new argument to pass to the free routine
oarg where the old argument to the free routine is returned. Can be NULL if no return is expected.
Returns:
the old free routine.

pmsg_check_t pmsg_set_check pmsg_t mb,
pmsg_check_t  check
 

Set the pre-send checking routine for the buffer.

This routine, if it exists (non-NULL) is called just before enqueueing the message for sending. If it returns FALSE, the message is immediately dropped.

The callback routine must not modify the message, as the buffer can be shared among multiple messages, unless its refcount is 1.

Returns:
the previous pre-send checking routine.

int pmsg_size pmsg_t mb  ) 
 

Compute message's size.

gint pmsg_write pmsg_t mb,
gconstpointer  data,
gint  len
 

Write data at the end of the message.

The message must be the only reference to the underlying data.

Returns:
amount of written data.

RCSID "$Id:pmsg.  c,
v 1.9 2005/06/25 01:37:40 daichik Exp $" 
 


Variable Documentation

zone_t* mb_zone = NULL [static]
 


Generated on Sun Feb 12 10:50:06 2006 for Gtk-Gnutella by doxygen 1.3.6