diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
commit | ac517a2b7625e0aa0862679e961c6349f859ea3b (patch) | |
tree | e3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/tests/itoqueue2.cpp | |
parent | f8d4301e9fa4f3709258505941e37fab2eadadc6 (diff) | |
parent | bd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff) | |
download | libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2 libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip |
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to 'src/tests/itoqueue2.cpp')
-rw-r--r-- | src/tests/itoqueue2.cpp | 83 |
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 | |||
6 | class Reader : public Bu::Ito | ||
7 | { | ||
8 | public: | ||
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 | |||
35 | private: | ||
36 | Bu::ItoQueue<std::string *> &q; | ||
37 | int id; | ||
38 | }; | ||
39 | |||
40 | class Writer : public Bu::Ito | ||
41 | { | ||
42 | public: | ||
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 | |||
62 | private: | ||
63 | Bu::ItoQueue<std::string *> &q; | ||
64 | const char *strbase; | ||
65 | int id; | ||
66 | }; | ||
67 | |||
68 | int 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 | |||