diff options
-rw-r--r-- | src/buffer.cpp | 14 | ||||
-rw-r--r-- | 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 @@ | |||
7 | 7 | ||
8 | #include "bu/buffer.h" | 8 | #include "bu/buffer.h" |
9 | 9 | ||
10 | Bu::Buffer::Buffer( Bu::Stream &rNext, int iBufSize ) : | 10 | Bu::Buffer::Buffer( Bu::Stream &rNext, int iWhat, int iBufSize ) : |
11 | Bu::Filter( rNext ), | 11 | Bu::Filter( rNext ), |
12 | sSoFar( 0 ), | 12 | sSoFar( 0 ), |
13 | iBufSize( iBufSize ), | 13 | iBufSize( iBufSize ), |
@@ -16,7 +16,8 @@ Bu::Buffer::Buffer( Bu::Stream &rNext, int iBufSize ) : | |||
16 | iReadBufFill( 0 ), | 16 | iReadBufFill( 0 ), |
17 | iReadPos( 0 ), | 17 | iReadPos( 0 ), |
18 | iWriteBufFill( 0 ), | 18 | iWriteBufFill( 0 ), |
19 | iWritePos( 0 ) | 19 | iWritePos( 0 ), |
20 | iWhat( iWhat ) | ||
20 | { | 21 | { |
21 | sReadBuf = new char[iBufSize]; | 22 | sReadBuf = new char[iBufSize]; |
22 | sWriteBuf = new char[iBufSize]; | 23 | sWriteBuf = new char[iBufSize]; |
@@ -51,6 +52,9 @@ void Bu::Buffer::fillReadBuf() | |||
51 | 52 | ||
52 | Bu::size Bu::Buffer::read( void *pBuf, Bu::size nBytes ) | 53 | Bu::size Bu::Buffer::read( void *pBuf, Bu::size nBytes ) |
53 | { | 54 | { |
55 | if( (iWhat&Read) == 0 ) | ||
56 | return rNext.read( pBuf, nBytes ); | ||
57 | |||
54 | if( nBytes <= 0 ) | 58 | if( nBytes <= 0 ) |
55 | { | 59 | { |
56 | fillReadBuf(); | 60 | fillReadBuf(); |
@@ -89,6 +93,9 @@ Bu::size Bu::Buffer::read( void *pBuf, Bu::size nBytes ) | |||
89 | 93 | ||
90 | Bu::size Bu::Buffer::write( const void *pBuf, Bu::size nBytes ) | 94 | Bu::size Bu::Buffer::write( const void *pBuf, Bu::size nBytes ) |
91 | { | 95 | { |
96 | if( (iWhat&Write) == 0 ) | ||
97 | return rNext.write( pBuf, nBytes ); | ||
98 | |||
92 | Bu::size nTotWrote = 0; | 99 | Bu::size nTotWrote = 0; |
93 | 100 | ||
94 | do | 101 | do |
@@ -137,6 +144,9 @@ Bu::size Bu::Buffer::write( const void *pBuf, Bu::size nBytes ) | |||
137 | 144 | ||
138 | void Bu::Buffer::flush() | 145 | void Bu::Buffer::flush() |
139 | { | 146 | { |
147 | if( (iWhat&Write) == 0 ) | ||
148 | return rNext.flush(); | ||
149 | |||
140 | if( iWriteBufFill > 0 ) | 150 | if( iWriteBufFill > 0 ) |
141 | { | 151 | { |
142 | //printf("Buffer: Flushing remaining data, %db.\n", iWriteBufFill ); | 152 | //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 | |||
15 | class Buffer : public Bu::Filter | 15 | class Buffer : public Bu::Filter |
16 | { | 16 | { |
17 | public: | 17 | public: |
18 | Buffer( Bu::Stream &rNext, int iBufSize=4096 ); | 18 | Buffer( Bu::Stream &rNext, int iWhat=Both, int iBufSize=4096 ); |
19 | virtual ~Buffer(); | 19 | virtual ~Buffer(); |
20 | 20 | ||
21 | enum | ||
22 | { | ||
23 | Write = 1, | ||
24 | Read = 2, | ||
25 | Both = 3 | ||
26 | }; | ||
27 | |||
21 | virtual void start(); | 28 | virtual void start(); |
22 | virtual Bu::size stop(); | 29 | virtual Bu::size stop(); |
23 | 30 | ||
@@ -44,6 +51,7 @@ namespace Bu | |||
44 | int iReadPos; | 51 | int iReadPos; |
45 | int iWriteBufFill; | 52 | int iWriteBufFill; |
46 | int iWritePos; | 53 | int iWritePos; |
54 | int iWhat; | ||
47 | }; | 55 | }; |
48 | }; | 56 | }; |
49 | 57 | ||