Source
mod = Py_InitModule3("buffer", Methods, "PQ Message buffer utilities");
/* $Id: buffer.c,v 1.1 2005/09/27 07:34:57 mww Exp $
*
* Copyright 2005, PostgresPy Project.
* http://python.projects.postgresql.org
*
*//*
* PQ message readers. Blocking dependent, and passive.
*
* PQ messages normally take the form type, (size), data.
* Passive and Block constructs a tuple from the read data.
*/
struct p_list
{
PyObject *data; /* PyString pushed onto the buffer */
struct p_list *next;
};
struct p_buffer
{
PyObject_HEAD
PyObject *message; /* NULL if the header has yet to be read */
char msg_type;
uint32_t msg_length;
uint32_t position; /* position in first */
uint32_t total; /* total data in the list */
struct p_list *first, *last;
};
/*
* Reset the buffer
*/
static void
p_truncate(struct p_buffer *pb)
{
struct p_list *pl = pb->first;
pb->total = 0;
pb->message = NULL;
pb->msg_type = '\0';
pb->msg_length = 0;
pb->position = 0;
pb->first = NULL;
pb->last = NULL;
while (pl != NULL)
{
struct p_list *next = pl->next;
Py_DECREF(pl->data);
free(pl);
pl = next;
}
}