diff options
Diffstat (limited to '')
| -rw-r--r-- | src/stable/client.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/stable/client.cpp b/src/stable/client.cpp index a9deb00..ca86f37 100644 --- a/src/stable/client.cpp +++ b/src/stable/client.cpp | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "bu/protocol.h" | 12 | #include "bu/protocol.h" |
| 13 | #include "bu/clientlink.h" | 13 | #include "bu/clientlink.h" |
| 14 | #include "bu/clientlinkfactory.h" | 14 | #include "bu/clientlinkfactory.h" |
| 15 | #include "bu/mutexlocker.h" | ||
| 15 | 16 | ||
| 16 | /** Read buffer size. */ | 17 | /** Read buffer size. */ |
| 17 | #define RBS (2000) // 1500 is the nominal MTU for ethernet, it's a good guess | 18 | #define RBS (2000) // 1500 is the nominal MTU for ethernet, it's a good guess |
| @@ -39,6 +40,7 @@ Bu::Client::~Client() | |||
| 39 | 40 | ||
| 40 | void Bu::Client::processInput() | 41 | void Bu::Client::processInput() |
| 41 | { | 42 | { |
| 43 | mRead.lock(); | ||
| 42 | char buf[RBS]; | 44 | char buf[RBS]; |
| 43 | Bu::size nRead, nTotal=0; | 45 | Bu::size nRead, nTotal=0; |
| 44 | 46 | ||
| @@ -67,6 +69,7 @@ void Bu::Client::processInput() | |||
| 67 | break; | 69 | break; |
| 68 | } | 70 | } |
| 69 | } | 71 | } |
| 72 | mRead.unlock(); | ||
| 70 | 73 | ||
| 71 | if( nTotal == 0 ) | 74 | if( nTotal == 0 ) |
| 72 | { | 75 | { |
| @@ -82,6 +85,7 @@ void Bu::Client::processInput() | |||
| 82 | 85 | ||
| 83 | void Bu::Client::processOutput() | 86 | void Bu::Client::processOutput() |
| 84 | { | 87 | { |
| 88 | mWrite.lock(); | ||
| 85 | char buf[RBS]; | 89 | char buf[RBS]; |
| 86 | if( qbWrite.getSize() > 0 ) | 90 | if( qbWrite.getSize() > 0 ) |
| 87 | { | 91 | { |
| @@ -91,6 +95,7 @@ void Bu::Client::processOutput() | |||
| 91 | qbWrite.seek( nReal ); | 95 | qbWrite.seek( nReal ); |
| 92 | pTopStream->flush(); | 96 | pTopStream->flush(); |
| 93 | } | 97 | } |
| 98 | mWrite.unlock(); | ||
| 94 | } | 99 | } |
| 95 | 100 | ||
| 96 | void Bu::Client::setProtocol( Protocol *pProto ) | 101 | void Bu::Client::setProtocol( Protocol *pProto ) |
| @@ -128,71 +133,85 @@ bool Bu::Client::isOpen() | |||
| 128 | 133 | ||
| 129 | Bu::size Bu::Client::write( const Bu::String &sData ) | 134 | Bu::size Bu::Client::write( const Bu::String &sData ) |
| 130 | { | 135 | { |
| 136 | Bu::MutexLocker l( mWrite ); | ||
| 131 | return qbWrite.write( sData.getStr(), sData.getSize() ); | 137 | return qbWrite.write( sData.getStr(), sData.getSize() ); |
| 132 | } | 138 | } |
| 133 | 139 | ||
| 134 | Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) | 140 | Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) |
| 135 | { | 141 | { |
| 142 | Bu::MutexLocker l( mWrite ); | ||
| 136 | return qbWrite.write( pData, nBytes ); | 143 | return qbWrite.write( pData, nBytes ); |
| 137 | } | 144 | } |
| 138 | 145 | ||
| 139 | Bu::size Bu::Client::write( int8_t nData ) | 146 | Bu::size Bu::Client::write( int8_t nData ) |
| 140 | { | 147 | { |
| 148 | Bu::MutexLocker l( mWrite ); | ||
| 141 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 149 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 142 | } | 150 | } |
| 143 | 151 | ||
| 144 | Bu::size Bu::Client::write( int16_t nData ) | 152 | Bu::size Bu::Client::write( int16_t nData ) |
| 145 | { | 153 | { |
| 154 | Bu::MutexLocker l( mWrite ); | ||
| 146 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 155 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 147 | } | 156 | } |
| 148 | 157 | ||
| 149 | Bu::size Bu::Client::write( int32_t nData ) | 158 | Bu::size Bu::Client::write( int32_t nData ) |
| 150 | { | 159 | { |
| 160 | Bu::MutexLocker l( mWrite ); | ||
| 151 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 161 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 152 | } | 162 | } |
| 153 | 163 | ||
| 154 | Bu::size Bu::Client::write( int64_t nData ) | 164 | Bu::size Bu::Client::write( int64_t nData ) |
| 155 | { | 165 | { |
| 166 | Bu::MutexLocker l( mWrite ); | ||
| 156 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 167 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 157 | } | 168 | } |
| 158 | 169 | ||
| 159 | Bu::size Bu::Client::write( uint8_t nData ) | 170 | Bu::size Bu::Client::write( uint8_t nData ) |
| 160 | { | 171 | { |
| 172 | Bu::MutexLocker l( mWrite ); | ||
| 161 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 173 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 162 | } | 174 | } |
| 163 | 175 | ||
| 164 | Bu::size Bu::Client::write( uint16_t nData ) | 176 | Bu::size Bu::Client::write( uint16_t nData ) |
| 165 | { | 177 | { |
| 178 | Bu::MutexLocker l( mWrite ); | ||
| 166 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 179 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 167 | } | 180 | } |
| 168 | 181 | ||
| 169 | Bu::size Bu::Client::write( uint32_t nData ) | 182 | Bu::size Bu::Client::write( uint32_t nData ) |
| 170 | { | 183 | { |
| 184 | Bu::MutexLocker l( mWrite ); | ||
| 171 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 185 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 172 | } | 186 | } |
| 173 | 187 | ||
| 174 | Bu::size Bu::Client::write( uint64_t nData ) | 188 | Bu::size Bu::Client::write( uint64_t nData ) |
| 175 | { | 189 | { |
| 190 | Bu::MutexLocker l( mWrite ); | ||
| 176 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 191 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
| 177 | } | 192 | } |
| 178 | 193 | ||
| 179 | Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) | 194 | Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) |
| 180 | { | 195 | { |
| 196 | Bu::MutexLocker l( mWrite ); | ||
| 181 | return qbRead.read( pData, nBytes ); | 197 | return qbRead.read( pData, nBytes ); |
| 182 | } | 198 | } |
| 183 | 199 | ||
| 184 | Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) | 200 | Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) |
| 185 | { | 201 | { |
| 202 | Bu::MutexLocker l( mWrite ); | ||
| 186 | return qbRead.peek( pData, nBytes, nOffset ); | 203 | return qbRead.peek( pData, nBytes, nOffset ); |
| 187 | } | 204 | } |
| 188 | 205 | ||
| 189 | Bu::size Bu::Client::getInputSize() | 206 | Bu::size Bu::Client::getInputSize() |
| 190 | { | 207 | { |
| 208 | Bu::MutexLocker l( mWrite ); | ||
| 191 | return qbRead.getSize(); | 209 | return qbRead.getSize(); |
| 192 | } | 210 | } |
| 193 | 211 | ||
| 194 | Bu::size Bu::Client::getOutputSize() | 212 | Bu::size Bu::Client::getOutputSize() |
| 195 | { | 213 | { |
| 214 | Bu::MutexLocker l( mWrite ); | ||
| 196 | return qbWrite.getSize(); | 215 | return qbWrite.getSize(); |
| 197 | } | 216 | } |
| 198 | 217 | ||
| @@ -240,6 +259,7 @@ Bu::size Bu::Client::tell() | |||
| 240 | 259 | ||
| 241 | void Bu::Client::seek( Bu::size offset ) | 260 | void Bu::Client::seek( Bu::size offset ) |
| 242 | { | 261 | { |
| 262 | Bu::MutexLocker l( mRead ); | ||
| 243 | return qbRead.seek( offset ); | 263 | return qbRead.seek( offset ); |
| 244 | } | 264 | } |
| 245 | 265 | ||
| @@ -265,6 +285,7 @@ void Bu::Client::flush() | |||
| 265 | 285 | ||
| 266 | bool Bu::Client::canRead() | 286 | bool Bu::Client::canRead() |
| 267 | { | 287 | { |
| 288 | Bu::MutexLocker l( mRead ); | ||
| 268 | return qbRead.getSize() > 0; | 289 | return qbRead.getSize() > 0; |
| 269 | } | 290 | } |
| 270 | 291 | ||
