aboutsummaryrefslogtreecommitdiff
path: root/src/stable/clientbuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/stable/clientbuf.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/stable/clientbuf.cpp b/src/stable/clientbuf.cpp
index 493e577..4e59120 100644
--- a/src/stable/clientbuf.cpp
+++ b/src/stable/clientbuf.cpp
@@ -2,10 +2,12 @@
2 2
3#include "bu/mutexlocker.h" 3#include "bu/mutexlocker.h"
4 4
5#include "bu/sio.h"
6
5Bu::ClientBuf::ClientBuf() : 7Bu::ClientBuf::ClientBuf() :
6 accClientRaw( *this ), 8 accClientRaw( *this ),
7 accServer( *this ), 9 accServer( *this ),
8 accClientFiltered( &accClient ), 10 //accClientFiltered( &accClientRaw ),
9 accClient( *this ) 11 accClient( *this )
10{ 12{
11} 13}
@@ -156,7 +158,7 @@ Bu::String Bu::ClientBuf::ClientAccessRaw::getLocation() const
156///////// 158/////////
157// ClientAccess 159// ClientAccess
158/// 160///
159 161#define accClientFiltered accClientRaw
160Bu::ClientBuf::ClientAccess::ClientAccess( Bu::ClientBuf &rBuf ) : 162Bu::ClientBuf::ClientAccess::ClientAccess( Bu::ClientBuf &rBuf ) :
161 rBuf( rBuf ) 163 rBuf( rBuf )
162{ 164{
@@ -173,16 +175,19 @@ void Bu::ClientBuf::ClientAccess::close()
173 175
174Bu::size Bu::ClientBuf::ClientAccess::read( void *pBufRaw, size iBytes ) 176Bu::size Bu::ClientBuf::ClientAccess::read( void *pBufRaw, size iBytes )
175{ 177{
178 Bu::println("ClientAccess::read( ptr, %1 )").arg( iBytes );
176 char *pBuf = (char *)pBufRaw; 179 char *pBuf = (char *)pBufRaw;
177 Bu::MutexLocker l( mAccess ); 180 Bu::MutexLocker l( mAccess );
178 // Read from QueueBuf first 181 // Read from QueueBuf first
179 Bu::size ps = qbPeek.read( pBuf, iBytes ); 182 Bu::size ps = qbPeek.read( pBuf, iBytes );
183 Bu::println("ClientAccess::read: attempted qbPeek, got %1\n>%2<").arg( ps ).arg( Bu::String(pBuf, ps) );
180 iBytes -= ps; 184 iBytes -= ps;
181 pBuf += ps; 185 pBuf += ps;
182 // Request space left? Try the client 186 // Request space left? Try the client
183 if( iBytes > 0 ) 187 if( iBytes > 0 )
184 { 188 {
185 ps += rBuf.accClientFiltered.read( pBuf, iBytes ); 189 ps += rBuf.accClientFiltered.read( pBuf, iBytes );
190 Bu::println("ClientAccess::read: attempted completion from socket buffer, got %1\n>%2<").arg( ps ).arg( Bu::String(pBuf, ps) );
186 } 191 }
187 return ps; 192 return ps;
188} 193}
@@ -190,22 +195,26 @@ Bu::size Bu::ClientBuf::ClientAccess::read( void *pBufRaw, size iBytes )
190Bu::size Bu::ClientBuf::ClientAccess::peek( void *pData, int iBytes, 195Bu::size Bu::ClientBuf::ClientAccess::peek( void *pData, int iBytes,
191 int iOffset ) 196 int iOffset )
192{ 197{
198 Bu::println("ClientAccess::peek( ptr, %1, %2 )").arg( iBytes ).arg( iOffset );
193 Bu::MutexLocker l( mAccess ); 199 Bu::MutexLocker l( mAccess );
194 // Do we have enough data in the peek buffer to handle this? 200 // Do we have enough data in the peek buffer to handle this?
195 if( qbPeek.getSize() < iBytes+iOffset ) 201 if( qbPeek.getSize() < iBytes+iOffset )
196 { 202 {
203 Bu::println("ClientAccess::peek: Insufficient buffered data (%1)").arg( qbPeek.getSize() );
197 // Nope, make an attempt to fill it in. 204 // Nope, make an attempt to fill it in.
198 int nDiff = iBytes-qbPeek.getSize(); 205 int nDiff = iBytes-qbPeek.getSize();
199 // We have to make our own buffer, since iBytes+nOffeset could be bigger 206 // We have to make our own buffer, since iBytes+nOffeset could be bigger
200 // than pData. 207 // than pData.
201 char *pTmp = new char[nDiff]; 208 char *pTmp = new char[nDiff];
202 Bu::size ps = rBuf.accClientFiltered.read( pTmp, nDiff ); 209 Bu::size ps = rBuf.accClientFiltered.read( pTmp, nDiff );
210 Bu::println("ClientAccess::peek: Tried to fill buffer, read %1 of needed %2\n>%3<").arg( ps ).arg( nDiff ).arg( Bu::String(pTmp, ps) );
203 if( ps > 0 ) 211 if( ps > 0 )
204 { 212 {
205 // Add the data read to the peek buffer. 213 // Add the data read to the peek buffer.
206 qbPeek.write( pTmp, ps ); 214 qbPeek.write( pTmp, ps );
207 } 215 }
208 delete[] pTmp; 216 delete[] pTmp;
217 Bu::println("ClientAccess::peek: buffer left with %1").arg( qbPeek.getSize() );
209 } 218 }
210 219
211 return qbPeek.peek( pData, iBytes, iOffset ); 220 return qbPeek.peek( pData, iBytes, iOffset );
@@ -225,13 +234,15 @@ Bu::size Bu::ClientBuf::ClientAccess::tell()
225 234
226void Bu::ClientBuf::ClientAccess::seek( Bu::size offset ) 235void Bu::ClientBuf::ClientAccess::seek( Bu::size offset )
227{ 236{
237 Bu::println("ClientAccess::seek( %1 )").arg( offset );
228 Bu::MutexLocker l( mAccess ); 238 Bu::MutexLocker l( mAccess );
229 // For this type of stream seek is basically a destructive skip. It's like 239 // For this type of stream seek is basically a destructive skip. It's like
230 // reading the data but with no output buffer. Let's remove data from the 240 // reading the data but with no output buffer. Let's remove data from the
231 // peek buffer first. 241 // peek buffer first.
232 if( qbPeek.getSize() > 0 ) 242 if( qbPeek.getSize() > 0 )
233 { 243 {
234 Bu::size amount = Bu::buMax( qbPeek.getSize(), offset ); 244 Bu::size amount = Bu::buMin( qbPeek.getSize(), offset );
245 Bu::println("ClientAccess::seek: buffered: %1, amount: %2").arg( qbPeek.getSize() ).arg( amount );
235 qbPeek.seek( amount ); 246 qbPeek.seek( amount );
236 offset -= amount; 247 offset -= amount;
237 } 248 }
@@ -239,6 +250,7 @@ void Bu::ClientBuf::ClientAccess::seek( Bu::size offset )
239 // If there's offset left, then apply it to the underlying stream 250 // If there's offset left, then apply it to the underlying stream
240 if( offset > 0 ) 251 if( offset > 0 )
241 { 252 {
253 Bu::println("ClientAccess::seek: seeking remaining %1 in socket buffer").arg( offset );
242 rBuf.accClientFiltered.seek( offset ); 254 rBuf.accClientFiltered.seek( offset );
243 } 255 }
244} 256}
@@ -329,6 +341,7 @@ Bu::String Bu::ClientBuf::ClientAccess::getLocation() const
329{ 341{
330 return "ClientBuf"; 342 return "ClientBuf";
331} 343}
344#undef accClientFiltered
332 345
333///////// 346/////////
334// ServerAccess 347// ServerAccess