diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/client.cpp | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to '')
-rw-r--r-- | src/stable/client.cpp | 220 |
1 files changed, 110 insertions, 110 deletions
diff --git a/src/stable/client.cpp b/src/stable/client.cpp index 7ae10f7..f5cc75f 100644 --- a/src/stable/client.cpp +++ b/src/stable/client.cpp | |||
@@ -14,307 +14,307 @@ | |||
14 | #include "bu/clientlinkfactory.h" | 14 | #include "bu/clientlinkfactory.h" |
15 | 15 | ||
16 | /** Read buffer size. */ | 16 | /** Read buffer size. */ |
17 | #define RBS (2000) // 1500 is the nominal MTU for ethernet, it's a good guess | 17 | #define RBS (2000) // 1500 is the nominal MTU for ethernet, it's a good guess |
18 | 18 | ||
19 | Bu::Client::Client( Bu::TcpSocket *pSocket, | 19 | Bu::Client::Client( Bu::TcpSocket *pSocket, |
20 | class Bu::ClientLinkFactory *pfLink ) : | 20 | class Bu::ClientLinkFactory *pfLink ) : |
21 | pTopStream( pSocket ), | 21 | pTopStream( pSocket ), |
22 | pSocket( pSocket ), | 22 | pSocket( pSocket ), |
23 | pProto( NULL ), | 23 | pProto( NULL ), |
24 | bWantsDisconnect( false ), | 24 | bWantsDisconnect( false ), |
25 | pfLink( pfLink ) | 25 | pfLink( pfLink ) |
26 | { | 26 | { |
27 | lFilts.prepend( pSocket ); | 27 | lFilts.prepend( pSocket ); |
28 | } | 28 | } |
29 | 29 | ||
30 | Bu::Client::~Client() | 30 | Bu::Client::~Client() |
31 | { | 31 | { |
32 | for( FilterList::iterator i = lFilts.begin(); i; i++ ) | 32 | for( FilterList::iterator i = lFilts.begin(); i; i++ ) |
33 | { | 33 | { |
34 | delete *i; | 34 | delete *i; |
35 | } | 35 | } |
36 | pTopStream = pSocket = NULL; | 36 | pTopStream = pSocket = NULL; |
37 | delete pfLink; | 37 | delete pfLink; |
38 | } | 38 | } |
39 | 39 | ||
40 | void Bu::Client::processInput() | 40 | void Bu::Client::processInput() |
41 | { | 41 | { |
42 | char buf[RBS]; | 42 | char buf[RBS]; |
43 | Bu::size nRead, nTotal=0; | 43 | Bu::size nRead, nTotal=0; |
44 | 44 | ||
45 | for(;;) | 45 | for(;;) |
46 | { | 46 | { |
47 | try | 47 | try |
48 | { | 48 | { |
49 | nRead = pTopStream->read( buf, RBS ); | 49 | nRead = pTopStream->read( buf, RBS ); |
50 | 50 | ||
51 | if( nRead == 0 ) | 51 | if( nRead == 0 ) |
52 | { | 52 | { |
53 | break; | 53 | break; |
54 | } | 54 | } |
55 | else | 55 | else |
56 | { | 56 | { |
57 | nTotal += nRead; | 57 | nTotal += nRead; |
58 | qbRead.write( buf, nRead ); | 58 | qbRead.write( buf, nRead ); |
59 | if( !pTopStream->canRead() ) | 59 | if( !pTopStream->canRead() ) |
60 | break; | 60 | break; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | catch( Bu::TcpSocketException &e ) | 63 | catch( Bu::TcpSocketException &e ) |
64 | { | 64 | { |
65 | pTopStream->close(); | 65 | pTopStream->close(); |
66 | bWantsDisconnect = true; | 66 | bWantsDisconnect = true; |
67 | break; | 67 | break; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | if( nTotal == 0 ) | 71 | if( nTotal == 0 ) |
72 | { | 72 | { |
73 | pTopStream->close(); | 73 | pTopStream->close(); |
74 | bWantsDisconnect = true; | 74 | bWantsDisconnect = true; |
75 | } | 75 | } |
76 | 76 | ||
77 | if( pProto && nTotal ) | 77 | if( pProto && nTotal ) |
78 | { | 78 | { |
79 | pProto->onNewData( this ); | 79 | pProto->onNewData( this ); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | void Bu::Client::processOutput() | 83 | void Bu::Client::processOutput() |
84 | { | 84 | { |
85 | char buf[RBS]; | 85 | char buf[RBS]; |
86 | if( qbWrite.getSize() > 0 ) | 86 | if( qbWrite.getSize() > 0 ) |
87 | { | 87 | { |
88 | int nAmnt = RBS; | 88 | int nAmnt = RBS; |
89 | nAmnt = qbWrite.peek( buf, nAmnt ); | 89 | nAmnt = qbWrite.peek( buf, nAmnt ); |
90 | int nReal = pTopStream->write( buf, nAmnt ); | 90 | int nReal = pTopStream->write( buf, nAmnt ); |
91 | qbWrite.seek( nReal ); | 91 | qbWrite.seek( nReal ); |
92 | pTopStream->flush(); | 92 | pTopStream->flush(); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | void Bu::Client::setProtocol( Protocol *pProto ) | 96 | void Bu::Client::setProtocol( Protocol *pProto ) |
97 | { | 97 | { |
98 | this->pProto = pProto; | 98 | this->pProto = pProto; |
99 | this->pProto->onNewConnection( this ); | 99 | this->pProto->onNewConnection( this ); |
100 | } | 100 | } |
101 | 101 | ||
102 | Bu::Protocol *Bu::Client::getProtocol() | 102 | Bu::Protocol *Bu::Client::getProtocol() |
103 | { | 103 | { |
104 | return pProto; | 104 | return pProto; |
105 | } | 105 | } |
106 | 106 | ||
107 | void Bu::Client::clearProtocol() | 107 | void Bu::Client::clearProtocol() |
108 | { | 108 | { |
109 | pProto = NULL; | 109 | pProto = NULL; |
110 | } | 110 | } |
111 | /* | 111 | /* |
112 | Bu::String &Bu::Client::getInput() | 112 | Bu::String &Bu::Client::getInput() |
113 | { | 113 | { |
114 | return sReadBuf; | 114 | return sReadBuf; |
115 | } | 115 | } |
116 | 116 | ||
117 | Bu::String &Bu::Client::getOutput() | 117 | Bu::String &Bu::Client::getOutput() |
118 | { | 118 | { |
119 | return sWriteBuf; | 119 | return sWriteBuf; |
120 | } | 120 | } |
121 | */ | 121 | */ |
122 | 122 | ||
123 | bool Bu::Client::isOpen() | 123 | bool Bu::Client::isOpen() |
124 | { | 124 | { |
125 | if( !pTopStream ) return false; | 125 | if( !pTopStream ) return false; |
126 | return pTopStream->isOpen(); | 126 | return pTopStream->isOpen(); |
127 | } | 127 | } |
128 | 128 | ||
129 | Bu::size Bu::Client::write( const Bu::String &sData ) | 129 | Bu::size Bu::Client::write( const Bu::String &sData ) |
130 | { | 130 | { |
131 | return qbWrite.write( sData.getStr(), sData.getSize() ); | 131 | return qbWrite.write( sData.getStr(), sData.getSize() ); |
132 | } | 132 | } |
133 | 133 | ||
134 | Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) | 134 | Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) |
135 | { | 135 | { |
136 | return qbWrite.write( pData, nBytes ); | 136 | return qbWrite.write( pData, nBytes ); |
137 | } | 137 | } |
138 | 138 | ||
139 | Bu::size Bu::Client::write( int8_t nData ) | 139 | Bu::size Bu::Client::write( int8_t nData ) |
140 | { | 140 | { |
141 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 141 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
142 | } | 142 | } |
143 | 143 | ||
144 | Bu::size Bu::Client::write( int16_t nData ) | 144 | Bu::size Bu::Client::write( int16_t nData ) |
145 | { | 145 | { |
146 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 146 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
147 | } | 147 | } |
148 | 148 | ||
149 | Bu::size Bu::Client::write( int32_t nData ) | 149 | Bu::size Bu::Client::write( int32_t nData ) |
150 | { | 150 | { |
151 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 151 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
152 | } | 152 | } |
153 | 153 | ||
154 | Bu::size Bu::Client::write( int64_t nData ) | 154 | Bu::size Bu::Client::write( int64_t nData ) |
155 | { | 155 | { |
156 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 156 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
157 | } | 157 | } |
158 | 158 | ||
159 | Bu::size Bu::Client::write( uint8_t nData ) | 159 | Bu::size Bu::Client::write( uint8_t nData ) |
160 | { | 160 | { |
161 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 161 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
162 | } | 162 | } |
163 | 163 | ||
164 | Bu::size Bu::Client::write( uint16_t nData ) | 164 | Bu::size Bu::Client::write( uint16_t nData ) |
165 | { | 165 | { |
166 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 166 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
167 | } | 167 | } |
168 | 168 | ||
169 | Bu::size Bu::Client::write( uint32_t nData ) | 169 | Bu::size Bu::Client::write( uint32_t nData ) |
170 | { | 170 | { |
171 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 171 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
172 | } | 172 | } |
173 | 173 | ||
174 | Bu::size Bu::Client::write( uint64_t nData ) | 174 | Bu::size Bu::Client::write( uint64_t nData ) |
175 | { | 175 | { |
176 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); | 176 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
177 | } | 177 | } |
178 | 178 | ||
179 | Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) | 179 | Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) |
180 | { | 180 | { |
181 | return qbRead.read( pData, nBytes ); | 181 | return qbRead.read( pData, nBytes ); |
182 | } | 182 | } |
183 | 183 | ||
184 | Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) | 184 | Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) |
185 | { | 185 | { |
186 | return qbRead.peek( pData, nBytes, nOffset ); | 186 | return qbRead.peek( pData, nBytes, nOffset ); |
187 | } | 187 | } |
188 | 188 | ||
189 | Bu::size Bu::Client::getInputSize() | 189 | Bu::size Bu::Client::getInputSize() |
190 | { | 190 | { |
191 | return qbRead.getSize(); | 191 | return qbRead.getSize(); |
192 | } | 192 | } |
193 | 193 | ||
194 | Bu::size Bu::Client::getOutputSize() | 194 | Bu::size Bu::Client::getOutputSize() |
195 | { | 195 | { |
196 | return qbWrite.getSize(); | 196 | return qbWrite.getSize(); |
197 | } | 197 | } |
198 | 198 | ||
199 | const Bu::TcpSocket *Bu::Client::getSocket() const | 199 | const Bu::TcpSocket *Bu::Client::getSocket() const |
200 | { | 200 | { |
201 | return pSocket; | 201 | return pSocket; |
202 | } | 202 | } |
203 | 203 | ||
204 | void Bu::Client::disconnect() | 204 | void Bu::Client::disconnect() |
205 | { | 205 | { |
206 | bWantsDisconnect = true; | 206 | bWantsDisconnect = true; |
207 | } | 207 | } |
208 | 208 | ||
209 | bool Bu::Client::wantsDisconnect() | 209 | bool Bu::Client::wantsDisconnect() |
210 | { | 210 | { |
211 | return bWantsDisconnect; | 211 | return bWantsDisconnect; |
212 | } | 212 | } |
213 | 213 | ||
214 | void Bu::Client::close() | 214 | void Bu::Client::close() |
215 | { | 215 | { |
216 | pTopStream->close(); | 216 | pTopStream->close(); |
217 | } | 217 | } |
218 | 218 | ||
219 | Bu::ClientLink *Bu::Client::getLink() | 219 | Bu::ClientLink *Bu::Client::getLink() |
220 | { | 220 | { |
221 | return pfLink->createLink( this ); | 221 | return pfLink->createLink( this ); |
222 | } | 222 | } |
223 | 223 | ||
224 | void Bu::Client::onMessage( const Bu::String &sMsg ) | 224 | void Bu::Client::onMessage( const Bu::String &sMsg ) |
225 | { | 225 | { |
226 | if( pProto ) | 226 | if( pProto ) |
227 | pProto->onMessage( this, sMsg ); | 227 | pProto->onMessage( this, sMsg ); |
228 | } | 228 | } |
229 | 229 | ||
230 | void Bu::Client::tick() | 230 | void Bu::Client::tick() |
231 | { | 231 | { |
232 | if( pProto ) | 232 | if( pProto ) |
233 | pProto->onTick( this ); | 233 | pProto->onTick( this ); |
234 | } | 234 | } |
235 | 235 | ||
236 | Bu::size Bu::Client::tell() | 236 | Bu::size Bu::Client::tell() |
237 | { | 237 | { |
238 | return 0; | 238 | return 0; |
239 | } | 239 | } |
240 | 240 | ||
241 | void Bu::Client::seek( Bu::size offset ) | 241 | void Bu::Client::seek( Bu::size offset ) |
242 | { | 242 | { |
243 | return qbRead.seek( offset ); | 243 | return qbRead.seek( offset ); |
244 | } | 244 | } |
245 | 245 | ||
246 | void Bu::Client::setPos( Bu::size ) | 246 | void Bu::Client::setPos( Bu::size ) |
247 | { | 247 | { |
248 | throw Bu::ExceptionBase(); | 248 | throw Bu::ExceptionBase(); |
249 | } | 249 | } |
250 | 250 | ||
251 | void Bu::Client::setPosEnd( Bu::size ) | 251 | void Bu::Client::setPosEnd( Bu::size ) |
252 | { | 252 | { |
253 | throw Bu::ExceptionBase(); | 253 | throw Bu::ExceptionBase(); |
254 | } | 254 | } |
255 | 255 | ||
256 | bool Bu::Client::isEos() | 256 | bool Bu::Client::isEos() |
257 | { | 257 | { |
258 | return true; | 258 | return true; |
259 | } | 259 | } |
260 | 260 | ||
261 | void Bu::Client::flush() | 261 | void Bu::Client::flush() |
262 | { | 262 | { |
263 | processOutput(); | 263 | processOutput(); |
264 | } | 264 | } |
265 | 265 | ||
266 | bool Bu::Client::canRead() | 266 | bool Bu::Client::canRead() |
267 | { | 267 | { |
268 | return qbRead.getSize() > 0; | 268 | return qbRead.getSize() > 0; |
269 | } | 269 | } |
270 | 270 | ||
271 | bool Bu::Client::canWrite() | 271 | bool Bu::Client::canWrite() |
272 | { | 272 | { |
273 | return true; | 273 | return true; |
274 | } | 274 | } |
275 | 275 | ||
276 | bool Bu::Client::isReadable() | 276 | bool Bu::Client::isReadable() |
277 | { | 277 | { |
278 | return true; | 278 | return true; |
279 | } | 279 | } |
280 | 280 | ||
281 | bool Bu::Client::isWritable() | 281 | bool Bu::Client::isWritable() |
282 | { | 282 | { |
283 | return true; | 283 | return true; |
284 | } | 284 | } |
285 | 285 | ||
286 | bool Bu::Client::isSeekable() | 286 | bool Bu::Client::isSeekable() |
287 | { | 287 | { |
288 | return false; | 288 | return false; |
289 | } | 289 | } |
290 | 290 | ||
291 | bool Bu::Client::isBlocking() | 291 | bool Bu::Client::isBlocking() |
292 | { | 292 | { |
293 | return false; | 293 | return false; |
294 | } | 294 | } |
295 | 295 | ||
296 | void Bu::Client::setBlocking( bool ) | 296 | void Bu::Client::setBlocking( bool ) |
297 | { | 297 | { |
298 | throw Bu::ExceptionBase(); | 298 | throw Bu::ExceptionBase(); |
299 | } | 299 | } |
300 | 300 | ||
301 | void Bu::Client::setSize( Bu::size ) | 301 | void Bu::Client::setSize( Bu::size ) |
302 | { | 302 | { |
303 | throw Bu::ExceptionBase(); | 303 | throw Bu::ExceptionBase(); |
304 | } | 304 | } |
305 | 305 | ||
306 | Bu::size Bu::Client::getSize() const | 306 | Bu::size Bu::Client::getSize() const |
307 | { | 307 | { |
308 | return 0; | 308 | return 0; |
309 | } | 309 | } |
310 | 310 | ||
311 | Bu::size Bu::Client::getBlockSize() const | 311 | Bu::size Bu::Client::getBlockSize() const |
312 | { | 312 | { |
313 | return pSocket->getBlockSize(); | 313 | return pSocket->getBlockSize(); |
314 | } | 314 | } |
315 | 315 | ||
316 | Bu::String Bu::Client::getLocation() const | 316 | Bu::String Bu::Client::getLocation() const |
317 | { | 317 | { |
318 | return pSocket->getLocation(); | 318 | return pSocket->getLocation(); |
319 | } | 319 | } |
320 | 320 | ||