aboutsummaryrefslogtreecommitdiff
path: root/src/stable/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/client.cpp')
-rw-r--r--src/stable/client.cpp21
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
40void Bu::Client::processInput() 41void 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
83void Bu::Client::processOutput() 86void 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
96void Bu::Client::setProtocol( Protocol *pProto ) 101void Bu::Client::setProtocol( Protocol *pProto )
@@ -128,71 +133,85 @@ bool Bu::Client::isOpen()
128 133
129Bu::size Bu::Client::write( const Bu::String &sData ) 134Bu::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
134Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) 140Bu::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
139Bu::size Bu::Client::write( int8_t nData ) 146Bu::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
144Bu::size Bu::Client::write( int16_t nData ) 152Bu::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
149Bu::size Bu::Client::write( int32_t nData ) 158Bu::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
154Bu::size Bu::Client::write( int64_t nData ) 164Bu::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
159Bu::size Bu::Client::write( uint8_t nData ) 170Bu::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
164Bu::size Bu::Client::write( uint16_t nData ) 176Bu::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
169Bu::size Bu::Client::write( uint32_t nData ) 182Bu::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
174Bu::size Bu::Client::write( uint64_t nData ) 188Bu::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
179Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) 194Bu::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
184Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) 200Bu::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
189Bu::size Bu::Client::getInputSize() 206Bu::size Bu::Client::getInputSize()
190{ 207{
208 Bu::MutexLocker l( mWrite );
191 return qbRead.getSize(); 209 return qbRead.getSize();
192} 210}
193 211
194Bu::size Bu::Client::getOutputSize() 212Bu::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
241void Bu::Client::seek( Bu::size offset ) 260void 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
266bool Bu::Client::canRead() 286bool Bu::Client::canRead()
267{ 287{
288 Bu::MutexLocker l( mRead );
268 return qbRead.getSize() > 0; 289 return qbRead.getSize() > 0;
269} 290}
270 291