diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2018-01-29 00:47:50 -0800 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2018-01-29 00:47:50 -0800 |
commit | 1cb0fc6ab3f05e37f8c4c0bf5549b320c8b89078 (patch) | |
tree | 1417fdcc919d74ca25dc33b27714d10dd169700e /src/stable/client.cpp | |
parent | 65ffc3b58ca865a7f83bf39290df1760c35b57f0 (diff) | |
download | libbu++-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.cpp | 32 |
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 | ||
31 | Bu::Client::~Client() | 32 | Bu::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 | ||
41 | void Bu::Client::processInput() | 43 | void 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 | ||
86 | void Bu::Client::processOutput() | 89 | void 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 | ||
101 | void Bu::Client::setProtocol( Protocol *pProto ) | 105 | void 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 | ||
107 | Bu::Protocol *Bu::Client::getProtocol() | 112 | Bu::Protocol *Bu::Client::getProtocol() |
108 | { | 113 | { |
114 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
109 | return pProto; | 115 | return pProto; |
110 | } | 116 | } |
111 | 117 | ||
112 | void Bu::Client::clearProtocol() | 118 | void 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 | ||
128 | bool Bu::Client::isOpen() | 135 | bool 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 | ||
134 | Bu::size Bu::Client::write( const Bu::String &sData ) | 142 | Bu::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 | ||
140 | Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) | 149 | Bu::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 | ||
146 | Bu::size Bu::Client::write( int8_t nData ) | 156 | Bu::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 | ||
152 | Bu::size Bu::Client::write( int16_t nData ) | 163 | Bu::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 | ||
158 | Bu::size Bu::Client::write( int32_t nData ) | 170 | Bu::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 | ||
164 | Bu::size Bu::Client::write( int64_t nData ) | 177 | Bu::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 | ||
170 | Bu::size Bu::Client::write( uint8_t nData ) | 184 | Bu::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 | ||
176 | Bu::size Bu::Client::write( uint16_t nData ) | 191 | Bu::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 | ||
182 | Bu::size Bu::Client::write( uint32_t nData ) | 198 | Bu::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 | ||
188 | Bu::size Bu::Client::write( uint64_t nData ) | 205 | Bu::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 | ||
194 | Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) | 212 | Bu::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 | ||
200 | Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) | 219 | Bu::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 | ||
206 | Bu::size Bu::Client::getInputSize() | 226 | Bu::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 | ||
212 | Bu::size Bu::Client::getOutputSize() | 233 | Bu::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 | ||
218 | const Bu::TcpSocket *Bu::Client::getSocket() const | 240 | const Bu::TcpSocket *Bu::Client::getSocket() const |
219 | { | 241 | { |
242 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
220 | return pSocket; | 243 | return pSocket; |
221 | } | 244 | } |
222 | 245 | ||
223 | void Bu::Client::disconnect() | 246 | void Bu::Client::disconnect() |
224 | { | 247 | { |
248 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
225 | bWantsDisconnect = true; | 249 | bWantsDisconnect = true; |
226 | } | 250 | } |
227 | 251 | ||
228 | bool Bu::Client::wantsDisconnect() | 252 | bool Bu::Client::wantsDisconnect() |
229 | { | 253 | { |
254 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
230 | return bWantsDisconnect; | 255 | return bWantsDisconnect; |
231 | } | 256 | } |
232 | 257 | ||
233 | void Bu::Client::close() | 258 | void Bu::Client::close() |
234 | { | 259 | { |
260 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
235 | pTopStream->close(); | 261 | pTopStream->close(); |
236 | } | 262 | } |
237 | 263 | ||
238 | Bu::ClientLink *Bu::Client::getLink() | 264 | Bu::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 | ||
243 | void Bu::Client::onMessage( const Bu::String &sMsg ) | 270 | void 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 | ||
249 | void Bu::Client::tick() | 277 | void 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 | ||
260 | void Bu::Client::seek( Bu::size offset ) | 289 | void 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 | ||
281 | void Bu::Client::flush() | 311 | void Bu::Client::flush() |
282 | { | 312 | { |
313 | Bu::ReadWriteMutex::ReadLocker lGlobal( mGlobal ); | ||
283 | processOutput(); | 314 | processOutput(); |
284 | } | 315 | } |
285 | 316 | ||
286 | bool Bu::Client::canRead() | 317 | bool 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 | } |