summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 2ea72a2..95008f9 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -173,8 +173,14 @@ void Bu::Client::write( uint64_t nData )
173 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 173 sWriteBuf.append( (const char *)&nData, sizeof(nData) );
174} 174}
175 175
176void Bu::Client::read( void *pData, int nBytes ) 176int Bu::Client::read( void *pData, int nBytes )
177{ 177{
178 if( nBytes > sReadBuf.getSize()-nRBOffset )
179 {
180 nBytes = sReadBuf.getSize()-nRBOffset;
181 if( nBytes <= 0 )
182 return 0;
183 }
178 memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes ); 184 memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes );
179 nRBOffset += nBytes; 185 nRBOffset += nBytes;
180 if( sReadBuf.getSize()-nRBOffset == 0 ) 186 if( sReadBuf.getSize()-nRBOffset == 0 )
@@ -192,11 +198,20 @@ void Bu::Client::read( void *pData, int nBytes )
192 sReadBuf.trimFront( nRBOffset ); 198 sReadBuf.trimFront( nRBOffset );
193 nRBOffset = 0; 199 nRBOffset = 0;
194 } 200 }
201
202 return nBytes;
195} 203}
196 204
197void Bu::Client::peek( void *pData, int nBytes, int nOffset ) 205int Bu::Client::peek( void *pData, int nBytes, int nOffset )
198{ 206{
207 if( nBytes+nOffset > sReadBuf.getSize()-nRBOffset )
208 {
209 nBytes = sReadBuf.getSize()-nRBOffset-nOffset;
210 if( nBytes <= 0 )
211 return 0;
212 }
199 memcpy( pData, sReadBuf.getStr()+nRBOffset+nOffset, nBytes ); 213 memcpy( pData, sReadBuf.getStr()+nRBOffset+nOffset, nBytes );
214 return nBytes;
200} 215}
201 216
202void Bu::Client::seek( int nBytes ) 217void Bu::Client::seek( int nBytes )