diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-06-08 05:37:45 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-06-08 05:37:45 +0000 |
commit | 5f2c95f9116f24ecd64b6361b6e22ce983732997 (patch) | |
tree | fb27ff3927d1843b759d99506e2e3a03c88d0ab8 /src/buffer.cpp | |
parent | 6fcf117c7543a6adec19a6afea0da7df087170ab (diff) | |
download | libbu++-5f2c95f9116f24ecd64b6361b6e22ce983732997.tar.gz libbu++-5f2c95f9116f24ecd64b6361b6e22ce983732997.tar.bz2 libbu++-5f2c95f9116f24ecd64b6361b6e22ce983732997.tar.xz libbu++-5f2c95f9116f24ecd64b6361b6e22ce983732997.zip |
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.
Diffstat (limited to 'src/buffer.cpp')
-rw-r--r-- | src/buffer.cpp | 14 |
1 files changed, 12 insertions, 2 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 ); |