diff options
author | Mike Buland <eichlan@xagasoft.com> | 2014-08-14 15:49:05 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2014-08-14 15:49:05 +0000 |
commit | c5f69c22ca51510da1674bf56982f8f1e3ca4a40 (patch) | |
tree | 344332bc84359d6da4e626ede92bf31ae5d1a52b /src/stable/protocoltelnet.cpp | |
parent | d55d73c7050e6452f18678e60b42a088175cb7ce (diff) | |
download | libbu++-c5f69c22ca51510da1674bf56982f8f1e3ca4a40.tar.gz libbu++-c5f69c22ca51510da1674bf56982f8f1e3ca4a40.tar.bz2 libbu++-c5f69c22ca51510da1674bf56982f8f1e3ca4a40.tar.xz libbu++-c5f69c22ca51510da1674bf56982f8f1e3ca4a40.zip |
Neither the Bu::Client class or the Bu::ProtocolTelnet class were threadsafe
and both really need to be. Bu::Client is used in multi-threaded applications
and has been for a while, so it's a no brainer. It may need a little bit more
safety added around variable access, but all the buffers are safe now.
ProtocolTelnet has it's own issus, and I should probably rework a few parts of
it before too long so we can better accomidate things like line editing.
Diffstat (limited to 'src/stable/protocoltelnet.cpp')
-rw-r--r-- | src/stable/protocoltelnet.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/stable/protocoltelnet.cpp b/src/stable/protocoltelnet.cpp index 1461b0e..153af57 100644 --- a/src/stable/protocoltelnet.cpp +++ b/src/stable/protocoltelnet.cpp | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | #include "bu/protocoltelnet.h" | 8 | #include "bu/protocoltelnet.h" |
9 | #include "bu/client.h" | 9 | #include "bu/client.h" |
10 | #include "bu/mutexlocker.h" | ||
10 | 11 | ||
11 | /* We apparently at least want defs for the lower 13, not sure we care about | 12 | /* We apparently at least want defs for the lower 13, not sure we care about |
12 | * the rest of the chars, maybe escape. | 13 | * the rest of the chars, maybe escape. |
@@ -81,11 +82,16 @@ Bu::ProtocolTelnet::~ProtocolTelnet() | |||
81 | 82 | ||
82 | void Bu::ProtocolTelnet::onNewConnection( Bu::Client *pClient ) | 83 | void Bu::ProtocolTelnet::onNewConnection( Bu::Client *pClient ) |
83 | { | 84 | { |
85 | mRead.lock(); | ||
86 | mWrite.lock(); | ||
84 | this->pClient = pClient; | 87 | this->pClient = pClient; |
88 | mWrite.unlock(); | ||
89 | mRead.unlock(); | ||
85 | } | 90 | } |
86 | 91 | ||
87 | void Bu::ProtocolTelnet::onNewData( Bu::Client *pClient ) | 92 | void Bu::ProtocolTelnet::onNewData( Bu::Client *pClient ) |
88 | { | 93 | { |
94 | MutexLocker l( mRead ); | ||
89 | char bc; | 95 | char bc; |
90 | int iLeft; | 96 | int iLeft; |
91 | while( (iLeft = pClient->getInputSize()) ) | 97 | while( (iLeft = pClient->getInputSize()) ) |
@@ -233,7 +239,9 @@ void Bu::ProtocolTelnet::onNewData( Bu::Client *pClient ) | |||
233 | sDataBuf += bc; | 239 | sDataBuf += bc; |
234 | if( oEcho.isLocalSet() && bEcho ) | 240 | if( oEcho.isLocalSet() && bEcho ) |
235 | { | 241 | { |
242 | mWrite.lock(); | ||
236 | pClient->write( &bc, 1 ); | 243 | pClient->write( &bc, 1 ); |
244 | mWrite.unlock(); | ||
237 | #ifdef __TELNET_DEBUG | 245 | #ifdef __TELNET_DEBUG |
238 | printf("%c", bc ); | 246 | printf("%c", bc ); |
239 | fflush( stdout ); | 247 | fflush( stdout ); |
@@ -246,7 +254,9 @@ void Bu::ProtocolTelnet::onNewData( Bu::Client *pClient ) | |||
246 | sDataBuf += bc; | 254 | sDataBuf += bc; |
247 | if( oEcho.isLocalSet() && bEcho ) | 255 | if( oEcho.isLocalSet() && bEcho ) |
248 | { | 256 | { |
257 | mWrite.lock(); | ||
249 | pClient->write( &bc, 1 ); | 258 | pClient->write( &bc, 1 ); |
259 | mWrite.unlock(); | ||
250 | } | 260 | } |
251 | } | 261 | } |
252 | } | 262 | } |
@@ -291,6 +301,7 @@ void Bu::ProtocolTelnet::write( const Bu::String &sData ) | |||
291 | 301 | ||
292 | void Bu::ProtocolTelnet::write( const char *pData, int iSize ) | 302 | void Bu::ProtocolTelnet::write( const char *pData, int iSize ) |
293 | { | 303 | { |
304 | Bu::MutexLocker l( mWrite ); | ||
294 | int iLast = 0, j; | 305 | int iLast = 0, j; |
295 | for( j = iLast; j < iSize; j++ ) | 306 | for( j = iLast; j < iSize; j++ ) |
296 | { | 307 | { |
@@ -323,11 +334,13 @@ void Bu::ProtocolTelnet::write( char cData ) | |||
323 | 334 | ||
324 | void Bu::ProtocolTelnet::flush() | 335 | void Bu::ProtocolTelnet::flush() |
325 | { | 336 | { |
337 | Bu::MutexLocker l( mWrite ); | ||
326 | pClient->flush(); | 338 | pClient->flush(); |
327 | } | 339 | } |
328 | 340 | ||
329 | void Bu::ProtocolTelnet::onWill( char cCode ) | 341 | void Bu::ProtocolTelnet::onWill( char cCode ) |
330 | { | 342 | { |
343 | Bu::MutexLocker l( mWrite ); | ||
331 | try | 344 | try |
332 | { | 345 | { |
333 | Option *pOpt = hOpts[cCode]; | 346 | Option *pOpt = hOpts[cCode]; |
@@ -353,6 +366,7 @@ void Bu::ProtocolTelnet::onWill( char cCode ) | |||
353 | 366 | ||
354 | void Bu::ProtocolTelnet::onWont( char cCode ) | 367 | void Bu::ProtocolTelnet::onWont( char cCode ) |
355 | { | 368 | { |
369 | Bu::MutexLocker l( mWrite ); | ||
356 | try | 370 | try |
357 | { | 371 | { |
358 | Option *pOpt = hOpts[cCode]; | 372 | Option *pOpt = hOpts[cCode]; |
@@ -370,6 +384,7 @@ void Bu::ProtocolTelnet::onWont( char cCode ) | |||
370 | 384 | ||
371 | void Bu::ProtocolTelnet::onDo( char cCode ) | 385 | void Bu::ProtocolTelnet::onDo( char cCode ) |
372 | { | 386 | { |
387 | Bu::MutexLocker l( mWrite ); | ||
373 | try | 388 | try |
374 | { | 389 | { |
375 | Option *pOpt = hOpts[cCode]; | 390 | Option *pOpt = hOpts[cCode]; |
@@ -395,6 +410,7 @@ void Bu::ProtocolTelnet::onDo( char cCode ) | |||
395 | 410 | ||
396 | void Bu::ProtocolTelnet::onDont( char cCode ) | 411 | void Bu::ProtocolTelnet::onDont( char cCode ) |
397 | { | 412 | { |
413 | Bu::MutexLocker l( mWrite ); | ||
398 | try | 414 | try |
399 | { | 415 | { |
400 | Option *pOpt = hOpts[cCode]; | 416 | Option *pOpt = hOpts[cCode]; |
@@ -467,7 +483,9 @@ void Bu::ProtocolTelnet::onCtlChar( char cChr ) | |||
467 | { | 483 | { |
468 | sDataBuf.resize( sDataBuf.getSize()-1 ); | 484 | sDataBuf.resize( sDataBuf.getSize()-1 ); |
469 | char buf[3] = { CH_BS, ' ', CH_BS }; | 485 | char buf[3] = { CH_BS, ' ', CH_BS }; |
486 | mWrite.lock(); | ||
470 | pClient->write( buf, 3 ); | 487 | pClient->write( buf, 3 ); |
488 | mWrite.unlock(); | ||
471 | } | 489 | } |
472 | } | 490 | } |
473 | break; | 491 | break; |