summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-22 20:12:50 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-22 20:12:50 +0000
commit47627be8e85b2169ab3d9f34b8819cacb083b5bf (patch)
treed1a321b51c602f09039472918bb27618749ac461 /src/tests
parent88004d87d513dcba767b1dae1e5199a89b22ce36 (diff)
downloadlibbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.tar.gz
libbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.tar.bz2
libbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.tar.xz
libbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.zip
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.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/conduit.cpp56
1 files changed, 56 insertions, 0 deletions
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 @@
1#include "bu/conduit.h"
2#include "bu/sio.h"
3#include "bu/ito.h"
4
5using namespace Bu;
6
7class Reader : public Bu::Ito
8{
9public:
10 Reader( Bu::Conduit &rCond ) :
11 rCond( rCond )
12 {
13 }
14
15 virtual ~Reader()
16 {
17 }
18
19protected:
20 virtual void run()
21 {
22 while( rCond.isOpen() )
23 {
24 char buf[1025];
25
26 sio << "Reading..." << sio.flush;
27 Bu::size iRead = rCond.read( buf, 1024 );
28 buf[iRead] = '\0';
29 sio << "got " << iRead << " >" << buf << "<" << sio.nl;
30 }
31
32 sio << "Conduit closed, exting thread." << sio.nl;
33 }
34
35private:
36 Bu::Conduit &rCond;
37};
38
39int main()
40{
41 Conduit c;
42 Reader r( c );
43 r.start();
44
45 sleep( 3 );
46 c.write("Hi there", 8 );
47 sleep( 3 );
48 c.write("Goodbye, soon.", 14 );
49 sleep( 3 );
50 c.write("...NOW!", 9 );
51 c.close();
52 sleep( 3 );
53
54 return 0;
55}
56