aboutsummaryrefslogtreecommitdiff
path: root/src/tests/conduit.cpp
blob: d8d9e03adeb946e47460945c8bf36ab44330ae45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
}