diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-03-22 20:12:50 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-03-22 20:12:50 +0000 |
commit | 47627be8e85b2169ab3d9f34b8819cacb083b5bf (patch) | |
tree | d1a321b51c602f09039472918bb27618749ac461 /src/tests | |
parent | 88004d87d513dcba767b1dae1e5199a89b22ce36 (diff) | |
download | libbu++-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 '')
-rw-r--r-- | src/tests/conduit.cpp | 56 |
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 | |||
5 | using namespace Bu; | ||
6 | |||
7 | class Reader : public Bu::Ito | ||
8 | { | ||
9 | public: | ||
10 | Reader( Bu::Conduit &rCond ) : | ||
11 | rCond( rCond ) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | virtual ~Reader() | ||
16 | { | ||
17 | } | ||
18 | |||
19 | protected: | ||
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 | |||
35 | private: | ||
36 | Bu::Conduit &rCond; | ||
37 | }; | ||
38 | |||
39 | int 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 | |||