aboutsummaryrefslogtreecommitdiff
path: root/src/conduit.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-22 20:12:50 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-22 20:12:50 +0000
commit47627be8e85b2169ab3d9f34b8819cacb083b5bf (patch)
treed1a321b51c602f09039472918bb27618749ac461 /src/conduit.cpp
parent88004d87d513dcba767b1dae1e5199a89b22ce36 (diff)
downloadlibbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.tar.gz
libbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.tar.bz2
libbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.tar.xz
libbu++-47627be8e85b2169ab3d9f34b8819cacb083b5bf.zip
Bu::Conduit now works exactly as it was advertised some time ago, it uses
Bu::QueueBuf and creates a really slick blocking inter-thread I/O system.
Diffstat (limited to 'src/conduit.cpp')
-rw-r--r--src/conduit.cpp226
1 files changed, 226 insertions, 0 deletions
diff --git a/src/conduit.cpp b/src/conduit.cpp
index bb99526..cfa93d8 100644
--- a/src/conduit.cpp
+++ b/src/conduit.cpp
@@ -5,3 +5,229 @@
5 * terms of the license contained in the file LICENSE. 5 * terms of the license contained in the file LICENSE.
6 */ 6 */
7 7
8#include "bu/conduit.h"
9
10Bu::Conduit::Conduit( int iBlockSize ) :
11 qb( iBlockSize ),
12 bBlocking( true ),
13 bOpen( true )
14{
15}
16
17Bu::Conduit::~Conduit()
18{
19}
20
21void Bu::Conduit::close()
22{
23 im.lock();
24// qb.close();
25 bOpen = false;
26
27 cBlock.signal();
28 im.unlock();
29}
30
31#include <stdio.h>
32Bu::size Bu::Conduit::read( void *pBuf, Bu::size nBytes )
33{
34 if( !isOpen() )
35 {
36 return 0;
37 }
38 im.lock();
39 if( bBlocking )
40 {
41 im.unlock();
42 cBlock.lock();
43 for(;;)
44 {
45 im.lock();
46 if( qb.getSize() == 0 && bOpen == false )
47 {
48 im.unlock();
49 cBlock.unlock();
50 return 0;
51 }
52 else if( qb.getSize() > 0 )
53 {
54 im.unlock();
55 break;
56 }
57 im.unlock();
58
59 cBlock.wait();
60 }
61
62 im.lock();
63 Bu::size iRet = qb.read( pBuf, nBytes );
64 im.unlock();
65
66 cBlock.unlock();
67 return iRet;
68 }
69 else
70 {
71 Bu::size iRet = qb.read( pBuf, nBytes );
72 im.unlock();
73
74 return iRet;
75 }
76}
77
78Bu::size Bu::Conduit::peek( void *pBuf, Bu::size nBytes )
79{
80 im.lock();
81 Bu::size iRet = qb.peek( pBuf, nBytes );
82 im.unlock();
83
84 return iRet;
85}
86
87Bu::size Bu::Conduit::peek( void *pBuf, Bu::size nBytes, Bu::size nSkip )
88{
89 im.lock();
90 Bu::size iRet = qb.peek( pBuf, nBytes, nSkip );
91 im.unlock();
92
93 return iRet;
94}
95
96Bu::size Bu::Conduit::write( const void *pBuf, Bu::size nBytes )
97{
98 im.lock();
99 if( bOpen == false )
100 {
101 im.unlock();
102 return 0;
103 }
104 Bu::size sRet = qb.write( pBuf, nBytes );
105 cBlock.signal();
106 im.unlock();
107
108 return sRet;
109}
110
111Bu::size Bu::Conduit::tell()
112{
113 im.lock();
114 Bu::size sRet = qb.tell();
115 im.unlock();
116 return sRet;
117}
118
119void Bu::Conduit::seek( Bu::size offset )
120{
121}
122
123void Bu::Conduit::setPos( Bu::size pos )
124{
125}
126
127void Bu::Conduit::setPosEnd( Bu::size pos )
128{
129}
130
131bool Bu::Conduit::isEos()
132{
133 im.lock();
134 bool bRet = qb.isEos();
135 im.unlock();
136 return bRet;
137}
138
139bool Bu::Conduit::isOpen()
140{
141 im.lock();
142 bool bRet = bOpen || (qb.getSize() > 0);
143 im.unlock();
144 return bRet;
145}
146
147void Bu::Conduit::flush()
148{
149}
150
151bool Bu::Conduit::canRead()
152{
153 im.lock();
154 bool bRet = qb.canRead();
155 im.unlock();
156 return bRet;
157}
158
159bool Bu::Conduit::canWrite()
160{
161 im.lock();
162 bool bRet = qb.canWrite();
163 im.unlock();
164 return bRet;
165}
166
167bool Bu::Conduit::isReadable()
168{
169 im.lock();
170 bool bRet = qb.isReadable();
171 im.unlock();
172 return bRet;
173}
174
175bool Bu::Conduit::isWritable()
176{
177 im.lock();
178 bool bRet = qb.isWritable();
179 im.unlock();
180 return bRet;
181}
182
183bool Bu::Conduit::isSeekable()
184{
185 im.lock();
186 bool bRet = qb.isSeekable();
187 im.unlock();
188 return bRet;
189}
190
191bool Bu::Conduit::isBlocking()
192{
193 im.lock();
194 bool bRet = bBlocking;
195 im.unlock();
196 return bRet;
197}
198
199void Bu::Conduit::setBlocking( bool bBlocking )
200{
201 im.lock();
202 this->bBlocking = bBlocking;
203 im.unlock();
204}
205
206void Bu::Conduit::setSize( Bu::size iSize )
207{
208}
209
210Bu::size Bu::Conduit::getSize() const
211{
212 im.lock();
213 Bu::size sRet = qb.getSize();
214 im.unlock();
215 return sRet;
216}
217
218Bu::size Bu::Conduit::getBlockSize() const
219{
220 im.lock();
221 Bu::size sRet = qb.getBlockSize();
222 im.unlock();
223 return sRet;
224}
225
226Bu::String Bu::Conduit::getLocation() const
227{
228 im.lock();
229 Bu::String sRet = qb.getLocation();
230 im.unlock();
231 return sRet;
232}
233