summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-03-27 21:05:10 +0000
committerMike Buland <eichlan@xagasoft.com>2007-03-27 21:05:10 +0000
commitbebc878b054a06ff8e541db695b1e586fff2b022 (patch)
tree031e2e141fc18450954e0323ea6de60328822575 /src
parent57191021fe365eb8d448a9f2a66002a59e2ab065 (diff)
downloadlibbu++-bebc878b054a06ff8e541db695b1e586fff2b022.tar.gz
libbu++-bebc878b054a06ff8e541db695b1e586fff2b022.tar.bz2
libbu++-bebc878b054a06ff8e541db695b1e586fff2b022.tar.xz
libbu++-bebc878b054a06ff8e541db695b1e586fff2b022.zip
Added a new helper to the flexbuf, and likewise to the connection class, since
it uses it heavily.
Diffstat (limited to '')
-rw-r--r--src/connection.cpp5
-rw-r--r--src/connection.h2
-rw-r--r--src/flexbuf.cpp23
-rw-r--r--src/flexbuf.h2
4 files changed, 32 insertions, 0 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index a5fac5b..f042705 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -29,6 +29,11 @@ Connection::~Connection()
29 if( pProtocol != NULL ) delete pProtocol; 29 if( pProtocol != NULL ) delete pProtocol;
30} 30}
31 31
32void Connection::ensureCapacity( int nSize )
33{
34 xOutputBuf.ensureCapacity( nSize );
35}
36
32bool Connection::appendOutput( const char *lpOutput, int nSize ) 37bool Connection::appendOutput( const char *lpOutput, int nSize )
33{ 38{
34 return xOutputBuf.appendData( lpOutput, nSize ); 39 return xOutputBuf.appendData( lpOutput, nSize );
diff --git a/src/connection.h b/src/connection.h
index 5d2d9bd..7e1141d 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -51,6 +51,8 @@ public:
51 */ 51 */
52 bool open( const char *sAddr, int nPort ); 52 bool open( const char *sAddr, int nPort );
53 53
54 void ensureCapacity( int nSize );
55
54 /** Append the given data to the output. The data is presumed to be null 56 /** Append the given data to the output. The data is presumed to be null
55 * terminated. To put binary data into the stream, use the other 57 * terminated. To put binary data into the stream, use the other
56 * appendOutput function. This should be the only method used to 58 * appendOutput function. This should be the only method used to
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 )
204 return -1; 204 return -1;
205} 205}
206 206
207void FlexBuf::ensureCapacity( int nAmount )
208{
209 if( nLastChar + nAmount + 1 > nSize )
210 {
211 if( nFill + nAmount + 1 < nSize )
212 {
213 memcpy( lpBuf, lpBuf+nFirstChar, nFill );
214 nLastChar -= nFirstChar;
215 nFirstChar = 0;
216 }
217 else
218 {
219 nSize += nAmount+1;
220 char *lpNewBuf = new char[nSize];
221 memcpy( lpNewBuf, lpBuf+nFirstChar, nFill );
222 delete[] lpBuf;
223 lpBuf = lpNewBuf;
224 nLastChar -= nFirstChar;
225 nFirstChar = 0;
226 }
227 }
228}
229
diff --git a/src/flexbuf.h b/src/flexbuf.h
index a68dcc6..7d7f11a 100644
--- a/src/flexbuf.h
+++ b/src/flexbuf.h
@@ -144,6 +144,8 @@ public:
144 */ 144 */
145 int findChar( char cTarget ); 145 int findChar( char cTarget );
146 146
147 void ensureCapacity( int nAmount );
148
147private: 149private:
148 /** The raw storage location of the FlexBuf. */ 150 /** The raw storage location of the FlexBuf. */
149 char *lpBuf; 151 char *lpBuf;