From c82dc43edc9fd913e8ddb20bebe778781ec0d6f7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 11 Sep 2007 04:05:26 +0000 Subject: 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. --- src/tests/itoserver.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/tests/itoserver.cpp (limited to 'src/tests') 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 @@ +#include "bu/itoserver.h" +#include "bu/protocol.h" +#include "bu/client.h" + +#define BU_TRACE +#include "bu/trace.h" + +class ProtocolEcho : public Bu::Protocol +{ +public: + ProtocolEcho() + { + TRACE(); + } + virtual ~ProtocolEcho() + { + TRACE(); + } + + virtual void onNewConnection( Bu::Client *pClient ) + { + TRACE(); + // Huh... + } + + virtual void onNewData( Bu::Client *pClient ) + { + TRACE(); + pClient->write( pClient->getInput().getStr(), pClient->getInputSize() ); + pClient->seek( pClient->getInputSize() ); + } +}; + +class TestServer : public Bu::ItoServer +{ +public: + TestServer() + { + TRACE(); + } + virtual ~TestServer() + { + TRACE(); + } + + virtual void onNewConnection( Bu::Client *pClient, int iPort ) + { + TRACE(); + pClient->setProtocol( new ProtocolEcho() ); + } + + virtual void onClosedConnection( Bu::Client *pClient ) + { + TRACE(); + delete pClient->getProtocol(); + } +}; + +int main() +{ + TRACE(); + + TestServer ts; + + ts.addPort( 5555 ); + ts.start(); + ts.join(); +} + -- cgit v1.2.3