SBuf issue

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Thu, 21 Nov 2013 22:27:57 +1300

While writing parser updates I have encountered the small problem that
SBuf always *copies* data from non-Sbuf sources. There is absolutely no
way provided to use a pre-allocated I/O buffer as the backing store for
Sbuf objects. This includes pointing SBuf at a already allocated global
char*.
 It always copies.

The way it is done makes sense in parsing where the input buffer is
constantly being cycled/shifted by the I/O system and possibly has 500KB
of area with a small sub-string needing to be pointed at by an SBuf for
long periods.
 However, is also prevents us from doing two things:
 1) having a global array of char* header names and field values. Which
the parser points an SBuf at before emitting (avoiding a lock on the I/O
buffer memory).

 2) having a sub-string of an existing buffer temporarily pointed to by
an SBuf for string comparision operations. eg
  char* ioBuffer[1024];
  ... do some read()
  if (ioBuffer[0] == 'X') {
    SBuf key(ioBuffer+1, 20);
    ... use key as a reference to the ioBuffer[1 - 20] sub-string ...
  }

this latter is what I am finding many needs for through the HTTP parser.
Primarily because parsing happens in small pieces and the end of a block
of input may not even be present when we have to scan the start of it.

Amos
Received on Thu Nov 21 2013 - 09:28:09 MST

This archive was generated by hypermail 2.2.0 : Thu Nov 21 2013 - 12:00:12 MST