From 47627be8e85b2169ab3d9f34b8819cacb083b5bf Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 22 Mar 2011 20:12:50 +0000 Subject: Bu::Conduit now works exactly as it was advertised some time ago, it uses Bu::QueueBuf and creates a really slick blocking inter-thread I/O system. --- src/tests/conduit.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/tests/conduit.cpp (limited to 'src/tests/conduit.cpp') diff --git a/src/tests/conduit.cpp b/src/tests/conduit.cpp new file mode 100644 index 0000000..d8d9e03 --- /dev/null +++ b/src/tests/conduit.cpp @@ -0,0 +1,56 @@ +#include "bu/conduit.h" +#include "bu/sio.h" +#include "bu/ito.h" + +using namespace Bu; + +class Reader : public Bu::Ito +{ +public: + Reader( Bu::Conduit &rCond ) : + rCond( rCond ) + { + } + + virtual ~Reader() + { + } + +protected: + virtual void run() + { + while( rCond.isOpen() ) + { + char buf[1025]; + + sio << "Reading..." << sio.flush; + Bu::size iRead = rCond.read( buf, 1024 ); + buf[iRead] = '\0'; + sio << "got " << iRead << " >" << buf << "<" << sio.nl; + } + + sio << "Conduit closed, exting thread." << sio.nl; + } + +private: + Bu::Conduit &rCond; +}; + +int main() +{ + Conduit c; + Reader r( c ); + r.start(); + + sleep( 3 ); + c.write("Hi there", 8 ); + sleep( 3 ); + c.write("Goodbye, soon.", 14 ); + sleep( 3 ); + c.write("...NOW!", 9 ); + c.close(); + sleep( 3 ); + + return 0; +} + -- cgit v1.2.3