From bebc878b054a06ff8e541db695b1e586fff2b022 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 27 Mar 2007 21:05:10 +0000 Subject: Added a new helper to the flexbuf, and likewise to the connection class, since it uses it heavily. --- src/flexbuf.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/flexbuf.cpp') diff --git a/src/flexbuf.cpp b/src/flexbuf.cpp index acd55a7..6d55294 100644 --- a/src/flexbuf.cpp +++ b/src/flexbuf.cpp @@ -204,3 +204,26 @@ int FlexBuf::findChar( char cTarget ) return -1; } +void FlexBuf::ensureCapacity( int nAmount ) +{ + if( nLastChar + nAmount + 1 > nSize ) + { + if( nFill + nAmount + 1 < nSize ) + { + memcpy( lpBuf, lpBuf+nFirstChar, nFill ); + nLastChar -= nFirstChar; + nFirstChar = 0; + } + else + { + nSize += nAmount+1; + char *lpNewBuf = new char[nSize]; + memcpy( lpNewBuf, lpBuf+nFirstChar, nFill ); + delete[] lpBuf; + lpBuf = lpNewBuf; + nLastChar -= nFirstChar; + nFirstChar = 0; + } + } +} + -- cgit v1.2.3