From 68f4dfa0e2996211a9439809df07e36614618a63 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 20 Mar 2008 03:21:59 +0000 Subject: This is a preliminary test of my new server simplification subclass, don't use it yet, the name will change. I really, really, really want the name to change. --- src/tests/multiserver.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/tests/multiserver.cpp (limited to 'src/tests') diff --git a/src/tests/multiserver.cpp b/src/tests/multiserver.cpp new file mode 100644 index 0000000..f22147d --- /dev/null +++ b/src/tests/multiserver.cpp @@ -0,0 +1,62 @@ +#include "bu/multiserver.h" +#include "bu/protocol.h" +#include "bu/client.h" + +class ProtocolRaw : public Bu::Protocol +{ +public: + virtual void onNewConnection( Bu::Client *pClient ) + { + pClient->write("Raw echo\n"); + } + + virtual void onNewData( Bu::Client *pClient ) + { + pClient->write( pClient->getInput() ); + pClient->seek( pClient->getInputSize() ); + } +}; + +class ProtocolRot13 : public Bu::Protocol +{ +public: + virtual void onNewConnection( Bu::Client *pClient ) + { + pClient->write("Rot13 echo\n"); + } + + virtual void onNewData( Bu::Client *pClient ) + { + Bu::FString sTmp = pClient->getInput(); + for( int j = 0; j < sTmp.getSize(); j++ ) + { + if( sTmp[j] >= 'a' && sTmp[j] <= 'z' ) + { + sTmp[j] = ((sTmp[j]-'a'+13)%26) + 'a'; + } + else if( sTmp[j] >= 'A' && sTmp[j] <= 'Z' ) + { + sTmp[j] = ((sTmp[j]-'A'+13)%26) + 'A'; + } + } + pClient->write( sTmp ); + pClient->seek( pClient->getInputSize() ); + } +}; + +int main() +{ + Bu::MultiServer msMain; + + msMain.addProtocol( Bu::genProtocol, 5550 ); + msMain.addProtocol( Bu::genProtocol, 5551 ); + msMain.setTimeout( 5, 0 ); + + for(;;) + { + msMain.scan(); + } + + return 0; +} + -- cgit v1.2.3