aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-09-11 04:05:26 +0000
committerMike Buland <eichlan@xagasoft.com>2007-09-11 04:05:26 +0000
commitc82dc43edc9fd913e8ddb20bebe778781ec0d6f7 (patch)
tree101382ab930a2fa895a0ca3ea9e781ac71a1a625 /src/tests
parentace50b182f318b96a87505aa3d6b509959d49544 (diff)
downloadlibbu++-c82dc43edc9fd913e8ddb20bebe778781ec0d6f7.tar.gz
libbu++-c82dc43edc9fd913e8ddb20bebe778781ec0d6f7.tar.bz2
libbu++-c82dc43edc9fd913e8ddb20bebe778781ec0d6f7.tar.xz
libbu++-c82dc43edc9fd913e8ddb20bebe778781ec0d6f7.zip
Everything seems to work with the new Bu::ItoServer class, it operates very,
very similarly to the Bu::Server class, except that every incoming connection gets it's own thread. This functionality may have to be tuned later, to allow for maintaining a pool of connections as an option, but this is fine for now.
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