aboutsummaryrefslogtreecommitdiff
path: root/src/tests/itoqueue2.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-26 15:06:49 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-26 15:06:49 +0000
commit530014a3cce53e86dce8917e98a4e86d02f176aa (patch)
treec667c996fb91692b101f75296206b8420f19bf73 /src/tests/itoqueue2.cpp
parent066282ae6de25cf92780dbdaa2fd70a033e95659 (diff)
downloadlibbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.gz
libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.bz2
libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.xz
libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.zip
Merged Ito and put it in the BU namespace. I should probably clean up the
formatting on the comments, some of the lines wrap, but I'm not too worried about it right now. I also fixed up the doxygen config and build.conf files so that everything is building nice and smooth now.
Diffstat (limited to 'src/tests/itoqueue2.cpp')
-rw-r--r--src/tests/itoqueue2.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/tests/itoqueue2.cpp b/src/tests/itoqueue2.cpp
new file mode 100644
index 0000000..f4b5e19
--- /dev/null
+++ b/src/tests/itoqueue2.cpp
@@ -0,0 +1,83 @@
1#include <string>
2#include "bu/ito.h"
3#include "bu/itoqueue.h"
4#include <errno.h>
5
6class Reader : public Bu::Ito
7{
8public:
9 Reader( Bu::ItoQueue<std::string *> &q, int id ) :
10 q( q ),
11 id( id )
12 {
13 }
14
15 void *run()
16 {
17 for( int i = 0; i < 10; i++ )
18 {
19 std::string *pStr = q.dequeue( 0, 500000 );
20 if( pStr == NULL )
21 {
22 printf("Null received...\n");
23 i--;
24 }
25 else
26 {
27 printf("[%d] read: %s\n", id, pStr->c_str() );
28 delete pStr;
29 }
30 }
31
32 return NULL;
33 }
34
35private:
36 Bu::ItoQueue<std::string *> &q;
37 int id;
38};
39
40class Writer : public Bu::Ito
41{
42public:
43 Writer( Bu::ItoQueue<std::string *> &q, int id, const char *strbase ) :
44 q( q ),
45 strbase( strbase ),
46 id( id )
47 {
48 }
49
50 void *run()
51 {
52 for( int i = 0; i < 11; i++ )
53 {
54 sleep( 2 );
55 printf("[%d] write: %s\n", id, strbase );
56 q.enqueue( new std::string( strbase ) );
57 }
58
59 return NULL;
60 }
61
62private:
63 Bu::ItoQueue<std::string *> &q;
64 const char *strbase;
65 int id;
66};
67
68int main()
69{
70 printf("ETIMEDOUT: %d\n", ETIMEDOUT );
71 Bu::ItoQueue<std::string *> q;
72 Writer wr( q, 0, "writer" );
73 Reader rd( q, 0 );
74
75 rd.start();
76 wr.start();
77
78 rd.join();
79 wr.join();
80
81 return 0;
82}
83