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

Reply via email to