summaryrefslogtreecommitdiff
path: root/src/tests/itoqueue2.cpp
diff options
context:
space:
mode:
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