summaryrefslogtreecommitdiff
path: root/src/tests/multiserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-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