aboutsummaryrefslogtreecommitdiff
path: root/src/tests/multiserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/multiserver.cpp')
-rw-r--r--src/tests/multiserver.cpp76
1 files changed, 0 insertions, 76 deletions
diff --git a/src/tests/multiserver.cpp b/src/tests/multiserver.cpp
deleted file mode 100644
index 12f4681..0000000
--- a/src/tests/multiserver.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/multiserver.h"
9#include "bu/protocol.h"
10#include "bu/client.h"
11
12class ProtocolRaw : public Bu::Protocol
13{
14public:
15 virtual void onNewConnection( Bu::Client *pClient )
16 {
17 pClient->write("Raw echo\n");
18 }
19
20 virtual void onNewData( Bu::Client *pClient )
21 {
22 char buf[1024];
23 while( pClient->hasInput() )
24 {
25 int iAmnt = pClient->read( buf, 1024 );
26 pClient->write( buf, iAmnt );
27 }
28 }
29};
30
31class ProtocolRot13 : public Bu::Protocol
32{
33public:
34 virtual void onNewConnection( Bu::Client *pClient )
35 {
36 pClient->write("Rot13 echo\n");
37 }
38
39 virtual void onNewData( Bu::Client *pClient )
40 {
41 while( pClient->hasInput() )
42 {
43 char sTmp[1024];
44 int iAmnt = pClient->read( sTmp, 1024 );
45 for( int j = 0; j < iAmnt; j++ )
46 {
47 if( sTmp[j] >= 'a' && sTmp[j] <= 'z' )
48 {
49 sTmp[j] = ((sTmp[j]-'a'+13)%26) + 'a';
50 }
51 else if( sTmp[j] >= 'A' && sTmp[j] <= 'Z' )
52 {
53 sTmp[j] = ((sTmp[j]-'A'+13)%26) + 'A';
54 }
55 }
56 pClient->write( sTmp, iAmnt );
57 }
58 }
59};
60
61int main()
62{
63 Bu::MultiServer msMain;
64
65 msMain.addProtocol( Bu::genProtocol<ProtocolRaw>, 5550 );
66 msMain.addProtocol( Bu::genProtocol<ProtocolRot13>, 5551 );
67 msMain.setTimeout( 5, 0 );
68
69 for(;;)
70 {
71 msMain.scan();
72 }
73
74 return 0;
75}
76