Some changes and new features for MemBuf to make it more class-like
- made sure that cleaning a buffer that has not been initialized yet does
not lead to coredumps (this is similar to deleting a null pointer in C++).
- Added consume() and append*() methods to allow the buffer to be used in a
consumer/producer pipe-like environment.
- Added content() and space() methods as the first step to hide buf and size
members that require consume() method to always shift content to keep a
copyf of buf member valid (in case somebody made a copy of it).
- Noted that spaceSize() logic assumes the buffer does not expand and is
0-terminated. This means that the following does not hold:
max_capacity == contentSize() + spaceSize()
Fortunately, max_capacity is a private member that nobody should be using
outside of MemBuf.cc
0-termination of a MemBuf? Can we make it explicit like string::c_str()?
- added hasContent() method
- Added public terminate() method because some HTTP parsing routines need it,
unfortunately.
- Added potentialSpaceSize() to report how much space can be available
after the buffer is grown to the max. Useful for callers that decide
whether they _will_ have the space to store new data that they can get
from somewhere.
- Use private copy and operator= methods to prevent us from creating a
copy of a MemBuf. MemBuf copies are bad because then two ->buf pointers
point to the same location and its not clear who should free the memory.
- Added a destructor that asserts if someone forgot to free ->buf. Good
for finding memory leaks.
Restriction on not copying MemBufs must be propogated to MemBuf users.
In many cases this means changing "static" MemBufs to pointers.