aboutsummaryrefslogtreecommitdiff
path: root/src/stable/client.cpp
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2018-01-29 00:47:50 -0800
committerMike Buland <mbuland@penny-arcade.com>2018-01-29 00:47:50 -0800
commit1cb0fc6ab3f05e37f8c4c0bf5549b320c8b89078 (patch)
tree1417fdcc919d74ca25dc33b27714d10dd169700e /src/stable/client.cpp
parent65ffc3b58ca865a7f83bf39290df1760c35b57f0 (diff)
downloadlibbu++-1cb0fc6ab3f05e37f8c4c0bf5549b320c8b89078.tar.gz
libbu++-1cb0fc6ab3f05e37f8c4c0bf5549b320c8b89078.tar.bz2
libbu++-1cb0fc6ab3f05e37f8c4c0bf5549b320c8b89078.tar.xz
libbu++-1cb0fc6ab3f05e37f8c4c0bf5549b320c8b89078.zip
Changes related to debugging an issue.
It may not have had as much to do with low-level protocol details, and a lot of this can be reverted, but I can't revert it right now. I'll look it over later in the week.
Diffstat (limited to 'src/stable/client.cpp')
-rw-r--r--src/stable/client.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/stable/client.cpp b/src/stable/client.cpp
index ca86f37..43ae83b 100644
--- a/src/stable/client.cpp
+++ b/src/stable/client.cpp
@@ -25,11 +25,13 @@ Bu::Client::Client( Bu::TcpSocket *pSocket,
25 bWantsDisconnect( false ), 25 bWantsDisconnect( false ),
26 pfLink( pfLink ) 26 pfLink( pfLink )
27{ 27{
28 Bu::ReadWriteMutex::WriteLocker lGlobal( mGlobal );
28 lFilts.prepend( pSocket ); 29 lFilts.prepend( pSocket );
29} 30}
30 31
31Bu::Client::~Client() 32Bu::Client::~Client()
32{ 33{
34 Bu::ReadWriteMutex::WriteLocker lGlobal( mGlobal );
33 for( FilterList::iterator i = lFilts.begin(); i; i++ ) 35 for( FilterList::iterator i = lFilts.begin(); i; i++ )
34 { 36 {
35 delete *i; 37 delete *i;
@@ -40,6 +42,7 @@ Bu::Client::~Client()
40 42
41void Bu::Client::processInput() 43void Bu::Client::processInput()
42{ 44{
45 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
43 mRead.lock(); 46 mRead.lock();
44 char buf[RBS]; 47 char buf[RBS];
45 Bu::size nRead, nTotal=0; 48 Bu::size nRead, nTotal=0;
@@ -85,6 +88,7 @@ void Bu::Client::processInput()
85 88
86void Bu::Client::processOutput() 89void Bu::Client::processOutput()
87{ 90{
91 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
88 mWrite.lock(); 92 mWrite.lock();
89 char buf[RBS]; 93 char buf[RBS];
90 if( qbWrite.getSize() > 0 ) 94 if( qbWrite.getSize() > 0 )
@@ -100,17 +104,20 @@ void Bu::Client::processOutput()
100 104
101void Bu::Client::setProtocol( Protocol *pProto ) 105void Bu::Client::setProtocol( Protocol *pProto )
102{ 106{
107 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
103 this->pProto = pProto; 108 this->pProto = pProto;
104 this->pProto->onNewConnection( this ); 109 this->pProto->onNewConnection( this );
105} 110}
106 111
107Bu::Protocol *Bu::Client::getProtocol() 112Bu::Protocol *Bu::Client::getProtocol()
108{ 113{
114 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
109 return pProto; 115 return pProto;
110} 116}
111 117
112void Bu::Client::clearProtocol() 118void Bu::Client::clearProtocol()
113{ 119{
120 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
114 pProto = NULL; 121 pProto = NULL;
115} 122}
116/* 123/*
@@ -127,127 +134,149 @@ Bu::String &Bu::Client::getOutput()
127 134
128bool Bu::Client::isOpen() 135bool Bu::Client::isOpen()
129{ 136{
137 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
130 if( !pTopStream ) return false; 138 if( !pTopStream ) return false;
131 return pTopStream->isOpen(); 139 return pTopStream->isOpen();
132} 140}
133 141
134Bu::size Bu::Client::write( const Bu::String &sData ) 142Bu::size Bu::Client::write( const Bu::String &sData )
135{ 143{
144 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
136 Bu::MutexLocker l( mWrite ); 145 Bu::MutexLocker l( mWrite );
137 return qbWrite.write( sData.getStr(), sData.getSize() ); 146 return qbWrite.write( sData.getStr(), sData.getSize() );
138} 147}
139 148
140Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) 149Bu::size Bu::Client::write( const void *pData, Bu::size nBytes )
141{ 150{
151 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
142 Bu::MutexLocker l( mWrite ); 152 Bu::MutexLocker l( mWrite );
143 return qbWrite.write( pData, nBytes ); 153 return qbWrite.write( pData, nBytes );
144} 154}
145 155
146Bu::size Bu::Client::write( int8_t nData ) 156Bu::size Bu::Client::write( int8_t nData )
147{ 157{
158 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
148 Bu::MutexLocker l( mWrite ); 159 Bu::MutexLocker l( mWrite );
149 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 160 return qbWrite.write( (const char *)&nData, sizeof(nData) );
150} 161}
151 162
152Bu::size Bu::Client::write( int16_t nData ) 163Bu::size Bu::Client::write( int16_t nData )
153{ 164{
165 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
154 Bu::MutexLocker l( mWrite ); 166 Bu::MutexLocker l( mWrite );
155 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 167 return qbWrite.write( (const char *)&nData, sizeof(nData) );
156} 168}
157 169
158Bu::size Bu::Client::write( int32_t nData ) 170Bu::size Bu::Client::write( int32_t nData )
159{ 171{
172 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
160 Bu::MutexLocker l( mWrite ); 173 Bu::MutexLocker l( mWrite );
161 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 174 return qbWrite.write( (const char *)&nData, sizeof(nData) );
162} 175}
163 176
164Bu::size Bu::Client::write( int64_t nData ) 177Bu::size Bu::Client::write( int64_t nData )
165{ 178{
179 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
166 Bu::MutexLocker l( mWrite ); 180 Bu::MutexLocker l( mWrite );
167 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 181 return qbWrite.write( (const char *)&nData, sizeof(nData) );
168} 182}
169 183
170Bu::size Bu::Client::write( uint8_t nData ) 184Bu::size Bu::Client::write( uint8_t nData )
171{ 185{
186 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
172 Bu::MutexLocker l( mWrite ); 187 Bu::MutexLocker l( mWrite );
173 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 188 return qbWrite.write( (const char *)&nData, sizeof(nData) );
174} 189}
175 190
176Bu::size Bu::Client::write( uint16_t nData ) 191Bu::size Bu::Client::write( uint16_t nData )
177{ 192{
193 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
178 Bu::MutexLocker l( mWrite ); 194 Bu::MutexLocker l( mWrite );
179 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 195 return qbWrite.write( (const char *)&nData, sizeof(nData) );
180} 196}
181 197
182Bu::size Bu::Client::write( uint32_t nData ) 198Bu::size Bu::Client::write( uint32_t nData )
183{ 199{
200 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
184 Bu::MutexLocker l( mWrite ); 201 Bu::MutexLocker l( mWrite );
185 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 202 return qbWrite.write( (const char *)&nData, sizeof(nData) );
186} 203}
187 204
188Bu::size Bu::Client::write( uint64_t nData ) 205Bu::size Bu::Client::write( uint64_t nData )
189{ 206{
207 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
190 Bu::MutexLocker l( mWrite ); 208 Bu::MutexLocker l( mWrite );
191 return qbWrite.write( (const char *)&nData, sizeof(nData) ); 209 return qbWrite.write( (const char *)&nData, sizeof(nData) );
192} 210}
193 211
194Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) 212Bu::size Bu::Client::read( void *pData, Bu::size nBytes )
195{ 213{
214 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
196 Bu::MutexLocker l( mWrite ); 215 Bu::MutexLocker l( mWrite );
197 return qbRead.read( pData, nBytes ); 216 return qbRead.read( pData, nBytes );
198} 217}
199 218
200Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) 219Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset )
201{ 220{
221 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
202 Bu::MutexLocker l( mWrite ); 222 Bu::MutexLocker l( mWrite );
203 return qbRead.peek( pData, nBytes, nOffset ); 223 return qbRead.peek( pData, nBytes, nOffset );
204} 224}
205 225
206Bu::size Bu::Client::getInputSize() 226Bu::size Bu::Client::getInputSize()
207{ 227{
228 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
208 Bu::MutexLocker l( mWrite ); 229 Bu::MutexLocker l( mWrite );
209 return qbRead.getSize(); 230 return qbRead.getSize();
210} 231}
211 232
212Bu::size Bu::Client::getOutputSize() 233Bu::size Bu::Client::getOutputSize()
213{ 234{
235 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
214 Bu::MutexLocker l( mWrite ); 236 Bu::MutexLocker l( mWrite );
215 return qbWrite.getSize(); 237 return qbWrite.getSize();
216} 238}
217 239
218const Bu::TcpSocket *Bu::Client::getSocket() const 240const Bu::TcpSocket *Bu::Client::getSocket() const
219{ 241{
242 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
220 return pSocket; 243 return pSocket;
221} 244}
222 245
223void Bu::Client::disconnect() 246void Bu::Client::disconnect()
224{ 247{
248 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
225 bWantsDisconnect = true; 249 bWantsDisconnect = true;
226} 250}
227 251
228bool Bu::Client::wantsDisconnect() 252bool Bu::Client::wantsDisconnect()
229{ 253{
254 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
230 return bWantsDisconnect; 255 return bWantsDisconnect;
231} 256}
232 257
233void Bu::Client::close() 258void Bu::Client::close()
234{ 259{
260 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
235 pTopStream->close(); 261 pTopStream->close();
236} 262}
237 263
238Bu::ClientLink *Bu::Client::getLink() 264Bu::ClientLink *Bu::Client::getLink()
239{ 265{
266 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
240 return pfLink->createLink( this ); 267 return pfLink->createLink( this );
241} 268}
242 269
243void Bu::Client::onMessage( const Bu::String &sMsg ) 270void Bu::Client::onMessage( const Bu::String &sMsg )
244{ 271{
272 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
245 if( pProto ) 273 if( pProto )
246 pProto->onMessage( this, sMsg ); 274 pProto->onMessage( this, sMsg );
247} 275}
248 276
249void Bu::Client::tick() 277void Bu::Client::tick()
250{ 278{
279 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
251 if( pProto ) 280 if( pProto )
252 pProto->onTick( this ); 281 pProto->onTick( this );
253} 282}
@@ -259,6 +288,7 @@ Bu::size Bu::Client::tell()
259 288
260void Bu::Client::seek( Bu::size offset ) 289void Bu::Client::seek( Bu::size offset )
261{ 290{
291 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
262 Bu::MutexLocker l( mRead ); 292 Bu::MutexLocker l( mRead );
263 return qbRead.seek( offset ); 293 return qbRead.seek( offset );
264} 294}
@@ -280,11 +310,13 @@ bool Bu::Client::isEos()
280 310
281void Bu::Client::flush() 311void Bu::Client::flush()
282{ 312{
313 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
283 processOutput(); 314 processOutput();
284} 315}
285 316
286bool Bu::Client::canRead() 317bool Bu::Client::canRead()
287{ 318{
319 Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal );
288 Bu::MutexLocker l( mRead ); 320 Bu::MutexLocker l( mRead );
289 return qbRead.getSize() > 0; 321 return qbRead.getSize() > 0;
290} 322}