From 5574841cc88412854b2cb94253152b3606803e2a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 Feb 2008 14:59:11 +0000 Subject: Corrected a very rare race condition in Bu::ItoServer where there was a chance that the client would disconnect so quickly that it would be cleaned up before it was properly accounted for. I apparently added something to MiniMacro a while ago...probably the end tags I think... --- src/itoserver.cpp | 3 ++- src/minimacro.cpp | 33 ++++++++++++++++++++++++++++++++- src/minimacro.h | 3 +++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/itoserver.cpp b/src/itoserver.cpp index 8bdd894..7426e8a 100644 --- a/src/itoserver.cpp +++ b/src/itoserver.cpp @@ -64,11 +64,12 @@ void Bu::ItoServer::addClient( int nSocket, int nPort ) { ItoClient *pC = new ItoClient( *this, nSocket, nPort, nTimeoutSec, nTimeoutUSec ); - pC->start(); imClients.lock(); hClients.insert( nSocket, pC ); imClients.unlock(); + + pC->start(); } void *Bu::ItoServer::run() diff --git a/src/minimacro.cpp b/src/minimacro.cpp index 2bd156c..1d2abf8 100644 --- a/src/minimacro.cpp +++ b/src/minimacro.cpp @@ -20,8 +20,9 @@ Bu::MiniMacro::~MiniMacro() Bu::FString Bu::MiniMacro::parse( const Bu::FString &sIn ) { + bContinue = true; Bu::FString sOut; - for( sCur = sIn.getStr(); *sCur; sCur++ ) + for( sCur = sIn.getStr(); *sCur && bContinue; sCur++ ) { if( *sCur == '{' ) { @@ -53,6 +54,8 @@ Bu::FString Bu::MiniMacro::parse( const Bu::FString &sIn ) } } + iLastPos = (int)sCur - (int)sIn.getStr(); + return sOut; } @@ -101,6 +104,29 @@ Bu::FString Bu::MiniMacro::parseCond() Bu::FString Bu::MiniMacro::parseCmd() { Bu::FString sOut; + const char *sNext = sCur; + for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ); + if( *sNext != '\0' ) + { + Bu::FString sName( sCur, (int)sNext-(int)sCur ); + if( sName == "end" ) + { + sCur = sNext; + bContinue = false; + return sOut; + } + else + { + throw Bu::ExceptionBase("Unknown command '%s'.", + sName.getStr() + ); + } + } + else + { + printf("Uh...?\n"); + } + printf("%20s\n", sCur ); return sOut; } @@ -142,3 +168,8 @@ const Bu::FString &Bu::MiniMacro::getvar( const Bu::FString &sName ) return hVars.get( sName ); } +int Bu::MiniMacro::getPosition() +{ + return iLastPos; +} + diff --git a/src/minimacro.h b/src/minimacro.h index 4349b19..f278666 100644 --- a/src/minimacro.h +++ b/src/minimacro.h @@ -70,6 +70,7 @@ namespace Bu void addVar( const Bu::FString &sName, const Bu::FString &sValue ); bool hasVar( const Bu::FString &sName ); const Bu::FString &getvar( const Bu::FString &sName ); + int getPosition(); private: const char *sCur; @@ -80,6 +81,8 @@ namespace Bu const Bu::FString &sIn, const Bu::FString &sFunc ); StrHash hVars; + bool bContinue; + int iLastPos; public: typedef Bu::List StrList; -- cgit v1.2.3