From 5f2c95f9116f24ecd64b6361b6e22ce983732997 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 8 Jun 2011 05:37:45 +0000 Subject: Hopefully nobody was using the buffer size parameter, if so, it's moved. Buffer now takes an extra parameter: what to buffer, read, write, or both. This winds up being important when dealing with blocking sockets and the like. --- src/buffer.cpp | 14 ++++++++++++-- src/buffer.h | 10 +++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/buffer.cpp b/src/buffer.cpp index b54f97e..47fab70 100644 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -7,7 +7,7 @@ #include "bu/buffer.h" -Bu::Buffer::Buffer( Bu::Stream &rNext, int iBufSize ) : +Bu::Buffer::Buffer( Bu::Stream &rNext, int iWhat, int iBufSize ) : Bu::Filter( rNext ), sSoFar( 0 ), iBufSize( iBufSize ), @@ -16,7 +16,8 @@ Bu::Buffer::Buffer( Bu::Stream &rNext, int iBufSize ) : iReadBufFill( 0 ), iReadPos( 0 ), iWriteBufFill( 0 ), - iWritePos( 0 ) + iWritePos( 0 ), + iWhat( iWhat ) { sReadBuf = new char[iBufSize]; sWriteBuf = new char[iBufSize]; @@ -51,6 +52,9 @@ void Bu::Buffer::fillReadBuf() Bu::size Bu::Buffer::read( void *pBuf, Bu::size nBytes ) { + if( (iWhat&Read) == 0 ) + return rNext.read( pBuf, nBytes ); + if( nBytes <= 0 ) { fillReadBuf(); @@ -89,6 +93,9 @@ Bu::size Bu::Buffer::read( void *pBuf, Bu::size nBytes ) Bu::size Bu::Buffer::write( const void *pBuf, Bu::size nBytes ) { + if( (iWhat&Write) == 0 ) + return rNext.write( pBuf, nBytes ); + Bu::size nTotWrote = 0; do @@ -137,6 +144,9 @@ Bu::size Bu::Buffer::write( const void *pBuf, Bu::size nBytes ) void Bu::Buffer::flush() { + if( (iWhat&Write) == 0 ) + return rNext.flush(); + if( iWriteBufFill > 0 ) { //printf("Buffer: Flushing remaining data, %db.\n", iWriteBufFill ); diff --git a/src/buffer.h b/src/buffer.h index 17c6d73..91ec9c2 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -15,9 +15,16 @@ namespace Bu class Buffer : public Bu::Filter { public: - Buffer( Bu::Stream &rNext, int iBufSize=4096 ); + Buffer( Bu::Stream &rNext, int iWhat=Both, int iBufSize=4096 ); virtual ~Buffer(); + enum + { + Write = 1, + Read = 2, + Both = 3 + }; + virtual void start(); virtual Bu::size stop(); @@ -44,6 +51,7 @@ namespace Bu int iReadPos; int iWriteBufFill; int iWritePos; + int iWhat; }; }; -- cgit v1.2.3