aboutsummaryrefslogtreecommitdiff
path: root/src/tests/itoqueue2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/itoqueue2.cpp')
-rw-r--r--src/tests/itoqueue2.cpp87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/tests/itoqueue2.cpp b/src/tests/itoqueue2.cpp
deleted file mode 100644
index 10bc566..0000000
--- a/src/tests/itoqueue2.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include <string>
9#include "bu/ito.h"
10#include "bu/itoqueue.h"
11#include <errno.h>
12#include <stdio.h>
13
14class Reader : public Bu::Ito
15{
16public:
17 Reader( Bu::ItoQueue<std::string *> &q, int id ) :
18 q( q ),
19 id( id )
20 {
21 }
22
23 void run()
24 {
25 for( int i = 0; i < 10; i++ )
26 {
27 std::string *pStr = q.dequeue( 0, 500000 );
28 if( pStr == NULL )
29 {
30 printf("Null received...\n");
31 i--;
32 }
33 else
34 {
35 printf("[%d] read: %s\n", id, pStr->c_str() );
36 delete pStr;
37 }
38 }
39 }
40
41private:
42 Bu::ItoQueue<std::string *> &q;
43 int id;
44};
45
46class Writer : public Bu::Ito
47{
48public:
49 Writer( Bu::ItoQueue<std::string *> &q, int id, const char *strbase ) :
50 q( q ),
51 strbase( strbase ),
52 id( id )
53 {
54 }
55
56 void run()
57 {
58 for( int i = 0; i < 11; i++ )
59 {
60 sleep( 2 );
61 printf("[%d] write: %s\n", id, strbase );
62 q.enqueue( new std::string( strbase ) );
63 }
64 }
65
66private:
67 Bu::ItoQueue<std::string *> &q;
68 const char *strbase;
69 int id;
70};
71
72int main()
73{
74 printf("ETIMEDOUT: %d\n", ETIMEDOUT );
75 Bu::ItoQueue<std::string *> q;
76 Writer wr( q, 0, "writer" );
77 Reader rd( q, 0 );
78
79 rd.start();
80 wr.start();
81
82 rd.join();
83 wr.join();
84
85 return 0;
86}
87