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

packetstream.c File Reference


Detailed Description

G2 packet stream parser.

Author:
Jeroen Asselman
Date:
2004

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "packetstream.h"

Data Structures

struct  g2packetstream_s

Functions

void g2_packetstream_init ()
void g2_packetstream_close ()
g2packetstream_tg2_packetstream_new (gpointer *connection)
 Allocate a new packet stream.

g2packetstream_tg2_packetstream_get (gpointer *connection)
 Get a packet stream for the given connection.

void g2_packetstream_free (gpointer *connection)
 Free a packet stream from memory.

int g2_packetstream_put_data (g2packetstream_t *stream, char *data, int length)
 Put data in a given packet stream.

g2packet_tg2_packetstream_get_packet (g2packetstream_t *stream)
 Get a packet from the packetstream.

int g2_packetstream_get_error (g2packetstream_t *stream, char **errormessage)
 Gets an error from the packetstream.


Variables

const int MAX_PACKET_SIZE = 1024 * 1024
 Maximum packet size.

GHashTable * by_connection


Function Documentation

void g2_packetstream_close  ) 
 

void g2_packetstream_free gpointer *  connection  ) 
 

Free a packet stream from memory.

g2packetstream_t* g2_packetstream_get gpointer *  connection  ) 
 

Get a packet stream for the given connection.

Returns the g2 packet stream associated with the given pointer. If no packetstream could be found, NULL is returned.

Parameters:
connection the connection to lookup.
Returns:
the packetstream associated with the given connection.

int g2_packetstream_get_error g2packetstream_t stream,
char **  errormessage
 

Gets an error from the packetstream.

Gets an error, if any, from the packetstream. Any error indication could indicate out of sync and as a result the connection should be dropped.

Parameters:
stream a pointer to the stream from which to retreive the error message.
errormessage a pointer where the errormessage string is written.
Returns:
0 on no error.

g2packet_t* g2_packetstream_get_packet g2packetstream_t stream  ) 
 

Get a packet from the packetstream.

Gets a packet from the packetstream, if there are no packets available, NULL is returned.

Parameters:
stream a pointer to the stream to retreive the packet from.
Returns:
a pointer to the packet, or NULL if no packets available.

void g2_packetstream_init  ) 
 

g2packetstream_t* g2_packetstream_new gpointer *  connection  ) 
 

Allocate a new packet stream.

Allocates a new packet stream with the given connection as an identifier. Or if the connection allready exists, the existing connection is returned.

Parameters:
connection will be used as the identifier later for lookup (get)
Returns:
a new g2packetstream.

int g2_packetstream_put_data g2packetstream_t stream,
char *  data,
int  length
 

Put data in a given packet stream.

Puts received data in the given packet stream.

Parameters:
stream a pointer to the stream to which the data shall be written.
data a pointer to the data that shall be written.
length the amount of data that shall be written.
Returns:
the amount of bytes expected to be read additionally, never put more data than was requested or packets might get lost. 0 is returned if a full packet has been read and should be retreived first.


Variable Documentation

GHashTable* by_connection
 

const int MAX_PACKET_SIZE = 1024 * 1024
 

Maximum packet size.


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