aboutsummaryrefslogtreecommitdiff
path: root/src/tests/multiserver.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-03-20 03:21:59 +0000
committerMike Buland <eichlan@xagasoft.com>2008-03-20 03:21:59 +0000
commit68f4dfa0e2996211a9439809df07e36614618a63 (patch)
tree7e86ff3cdb8863629c77aa50b6b922678ce2cb4c /src/tests/multiserver.cpp
parent6c27b9b4024331558e6a719293f2b44a6ae77c28 (diff)
downloadlibbu++-68f4dfa0e2996211a9439809df07e36614618a63.tar.gz
libbu++-68f4dfa0e2996211a9439809df07e36614618a63.tar.bz2
libbu++-68f4dfa0e2996211a9439809df07e36614618a63.tar.xz
libbu++-68f4dfa0e2996211a9439809df07e36614618a63.zip
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.
Diffstat (limited to 'src/tests/multiserver.cpp')
-rw-r--r--src/tests/multiserver.cpp62
1 files changed, 62 insertions, 0 deletions
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 @@
1#include "bu/multiserver.h"
2#include "bu/protocol.h"
3#include "bu/client.h"
4
5class ProtocolRaw : public Bu::Protocol
6{
7public:
8 virtual void onNewConnection( Bu::Client *pClient )
9 {
10 pClient->write("Raw echo\n");
11 }
12
13 virtual void onNewData( Bu::Client *pClient )
14 {
15 pClient->write( pClient->getInput() );
16 pClient->seek( pClient->getInputSize() );
17 }
18};
19
20class ProtocolRot13 : public Bu::Protocol
21{
22public:
23 virtual void onNewConnection( Bu::Client *pClient )
24 {
25 pClient->write("Rot13 echo\n");
26 }
27
28 virtual void onNewData( Bu::Client *pClient )
29 {
30 Bu::FString sTmp = pClient->getInput();
31 for( int j = 0; j < sTmp.getSize(); j++ )
32 {
33 if( sTmp[j] >= 'a' && sTmp[j] <= 'z' )
34 {
35 sTmp[j] = ((sTmp[j]-'a'+13)%26) + 'a';
36 }
37 else if( sTmp[j] >= 'A' && sTmp[j] <= 'Z' )
38 {
39 sTmp[j] = ((sTmp[j]-'A'+13)%26) + 'A';
40 }
41 }
42 pClient->write( sTmp );
43 pClient->seek( pClient->getInputSize() );
44 }
45};
46
47int main()
48{
49 Bu::MultiServer msMain;
50
51 msMain.addProtocol( Bu::genProtocol<ProtocolRaw>, 5550 );
52 msMain.addProtocol( Bu::genProtocol<ProtocolRot13>, 5551 );
53 msMain.setTimeout( 5, 0 );
54
55 for(;;)
56 {
57 msMain.scan();
58 }
59
60 return 0;
61}
62