aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tests/itoserver.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/tests/itoserver.cpp b/src/tests/itoserver.cpp
new file mode 100644
index 0000000..4f5c644
--- /dev/null
+++ b/src/tests/itoserver.cpp
@@ -0,0 +1,69 @@
1#include "bu/itoserver.h"
2#include "bu/protocol.h"
3#include "bu/client.h"
4
5#define BU_TRACE
6#include "bu/trace.h"
7
8class ProtocolEcho : public Bu::Protocol
9{
10public:
11 ProtocolEcho()
12 {
13 TRACE();
14 }
15 virtual ~ProtocolEcho()
16 {
17 TRACE();
18 }
19
20 virtual void onNewConnection( Bu::Client *pClient )
21 {
22 TRACE();
23 // Huh...
24 }
25
26 virtual void onNewData( Bu::Client *pClient )
27 {
28 TRACE();
29 pClient->write( pClient->getInput().getStr(), pClient->getInputSize() );
30 pClient->seek( pClient->getInputSize() );
31 }
32};
33
34class TestServer : public Bu::ItoServer
35{
36public:
37 TestServer()
38 {
39 TRACE();
40 }
41 virtual ~TestServer()
42 {
43 TRACE();
44 }
45
46 virtual void onNewConnection( Bu::Client *pClient, int iPort )
47 {
48 TRACE();
49 pClient->setProtocol( new ProtocolEcho() );
50 }
51
52 virtual void onClosedConnection( Bu::Client *pClient )
53 {
54 TRACE();
55 delete pClient->getProtocol();
56 }
57};
58
59int main()
60{
61 TRACE();
62
63 TestServer ts;
64
65 ts.addPort( 5555 );
66 ts.start();
67 ts.join();
68}
69