Skip to content

Commit

Permalink
Performance boost in reassembler - removed unnecessary StringIO::skip
Browse files Browse the repository at this point in the history
darcs-hash:20090503123101-f1522-8d5651d46ca7a519230aa790a2ae0599ba451479.gz
  • Loading branch information
scudette committed May 3, 2009
1 parent bedc7aa commit fda6877
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/network/pypcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ static int PyPCAP_fill_buffer(PyPCAP *self, PyObject *fd) {
if(!buff) return -1;

// Append the data to the end:
CALL(self->buffer, skip, self->buffer->readptr);
CALL(self->buffer, seek, 0, SEEK_END);

// Copy the data into our buffer:
CALL(self->buffer, write, buff, len);
CALL(self->buffer, seek, 0, SEEK_SET);

self->buffer->readptr = current_readptr;
// self->buffer->readptr = current_readptr;

// Finished with the data
Py_DECREF(data);
Expand Down Expand Up @@ -107,7 +109,7 @@ static int PyPCAP_init(PyPCAP *self, PyObject *args, PyObject *kwds) {
self->pcap_offset = self->buffer->readptr;

// Skip over the file header:
CALL(self->buffer, skip, self->buffer->readptr);
// CALL(self->buffer, skip, self->buffer->readptr);

// Take over the fd
self->fd = fd;
Expand Down Expand Up @@ -215,14 +217,17 @@ static PyObject *PyPCAP_dissect(PyPCAP *self, PyObject *args, PyObject *kwds) {
static PyObject *PyPCAP_next(PyPCAP *self) {
PyObject *result;
int len;
int packet_offset;

// Make sure our buffer is full enough:
if(self->buffer->size < MAX_PACKET_SIZE) {
if(self->buffer->size - self->buffer->readptr < MAX_PACKET_SIZE) {
len = PyPCAP_fill_buffer(self, self->fd);

if(len<0) return NULL;
};

packet_offset = self->buffer->readptr;

/** This is an interesting side effect of the talloc reference model:
talloc_reference(context, ptr) adds a new context to ptr so ptr is
Expand Down Expand Up @@ -266,8 +271,8 @@ static PyObject *PyPCAP_next(PyPCAP *self) {
self->packet_header->header.offset = self->pcap_offset;

// Keep track of our own file offset:
self->pcap_offset += self->buffer->readptr;
CALL(self->buffer, skip, self->buffer->readptr);
self->pcap_offset += self->buffer->readptr - packet_offset;
// CALL(self->buffer, skip, self->buffer->readptr);

// Adjust the output endianess if needed
switch(self->output_format) {
Expand Down
2 changes: 1 addition & 1 deletion src/network/pypcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ typedef struct {
} PyPCAP;


#define FILL_SIZE (1024 * 100)
#define FILL_SIZE (1024 * 1000)

#endif

0 comments on commit fda6877

Please sign in to comment.