diff options
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 | |||
