aboutsummaryrefslogtreecommitdiff
path: root/src/stable/client.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/stable/client.cpp
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-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.cpp220
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
19Bu::Client::Client( Bu::TcpSocket *pSocket, 19Bu::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
30Bu::Client::~Client() 30Bu::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
40void Bu::Client::processInput() 40void 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
83void Bu::Client::processOutput() 83void 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
96void Bu::Client::setProtocol( Protocol *pProto ) 96void 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
102Bu::Protocol *Bu::Client::getProtocol() 102Bu::Protocol *Bu::Client::getProtocol()
103{ 103{
104 return pProto; 104 return pProto;
105} 105}
106 106
107void Bu::Client::clearProtocol() 107void Bu::Client::clearProtocol()
108{ 108{
109 pProto = NULL; 109 pProto = NULL;
110} 110}
111/* 111/*
112Bu::String &Bu::Client::getInput() 112Bu::String &Bu::Client::getInput()
113{ 113{
114 return sReadBuf; 114 return sReadBuf;
115} 115}
116 116
117Bu::String &Bu::Client::getOutput() 117Bu::String &Bu::Client::getOutput()
118{ 118{
119 return sWriteBuf; 119 return sWriteBuf;
120} 120}
121*/ 121*/
122 122
123bool Bu::Client::isOpen() 123bool 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
129Bu::size Bu::Client::write( const Bu::String &sData ) 129Bu::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
134Bu::size Bu::Client::write( const void *pData, Bu::size nBytes ) 134Bu::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
139Bu::size Bu::Client::write( int8_t nData ) 139Bu::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
144Bu::size Bu::Client::write( int16_t nData ) 144Bu::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
149Bu::size Bu::Client::write( int32_t nData ) 149Bu::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
154Bu::size Bu::Client::write( int64_t nData ) 154Bu::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
159Bu::size Bu::Client::write( uint8_t nData ) 159Bu::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
164Bu::size Bu::Client::write( uint16_t nData ) 164Bu::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
169Bu::size Bu::Client::write( uint32_t nData ) 169Bu::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
174Bu::size Bu::Client::write( uint64_t nData ) 174Bu::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
179Bu::size Bu::Client::read( void *pData, Bu::size nBytes ) 179Bu::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
184Bu::size Bu::Client::peek( void *pData, int nBytes, int nOffset ) 184Bu::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
189Bu::size Bu::Client::getInputSize() 189Bu::size Bu::Client::getInputSize()
190{ 190{
191 return qbRead.getSize(); 191 return qbRead.getSize();
192} 192}
193 193
194Bu::size Bu::Client::getOutputSize() 194Bu::size Bu::Client::getOutputSize()
195{ 195{
196 return qbWrite.getSize(); 196 return qbWrite.getSize();
197} 197}
198 198
199const Bu::TcpSocket *Bu::Client::getSocket() const 199const Bu::TcpSocket *Bu::Client::getSocket() const
200{ 200{
201 return pSocket; 201 return pSocket;
202} 202}
203 203
204void Bu::Client::disconnect() 204void Bu::Client::disconnect()
205{ 205{
206 bWantsDisconnect = true; 206 bWantsDisconnect = true;
207} 207}
208 208
209bool Bu::Client::wantsDisconnect() 209bool Bu::Client::wantsDisconnect()
210{ 210{
211 return bWantsDisconnect; 211 return bWantsDisconnect;
212} 212}
213 213
214void Bu::Client::close() 214void Bu::Client::close()
215{ 215{
216 pTopStream->close(); 216 pTopStream->close();
217} 217}
218 218
219Bu::ClientLink *Bu::Client::getLink() 219Bu::ClientLink *Bu::Client::getLink()
220{ 220{
221 return pfLink->createLink( this ); 221 return pfLink->createLink( this );
222} 222}
223 223
224void Bu::Client::onMessage( const Bu::String &sMsg ) 224void 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
230void Bu::Client::tick() 230void Bu::Client::tick()
231{ 231{
232 if( pProto ) 232 if( pProto )
233 pProto->onTick( this ); 233 pProto->onTick( this );
234} 234}
235 235
236Bu::size Bu::Client::tell() 236Bu::size Bu::Client::tell()
237{ 237{
238 return 0; 238 return 0;
239} 239}
240 240
241void Bu::Client::seek( Bu::size offset ) 241void Bu::Client::seek( Bu::size offset )
242{ 242{
243 return qbRead.seek( offset ); 243 return qbRead.seek( offset );
244} 244}
245 245
246void Bu::Client::setPos( Bu::size ) 246void Bu::Client::setPos( Bu::size )
247{ 247{
248 throw Bu::ExceptionBase(); 248 throw Bu::ExceptionBase();
249} 249}
250 250
251void Bu::Client::setPosEnd( Bu::size ) 251void Bu::Client::setPosEnd( Bu::size )
252{ 252{
253 throw Bu::ExceptionBase(); 253 throw Bu::ExceptionBase();
254} 254}
255 255
256bool Bu::Client::isEos() 256bool Bu::Client::isEos()
257{ 257{
258 return true; 258 return true;
259} 259}
260 260
261void Bu::Client::flush() 261void Bu::Client::flush()
262{ 262{
263 processOutput(); 263 processOutput();
264} 264}
265 265
266bool Bu::Client::canRead() 266bool Bu::Client::canRead()
267{ 267{
268 return qbRead.getSize() > 0; 268 return qbRead.getSize() > 0;
269} 269}
270 270
271bool Bu::Client::canWrite() 271bool Bu::Client::canWrite()
272{ 272{
273 return true; 273 return true;
274} 274}
275 275
276bool Bu::Client::isReadable() 276bool Bu::Client::isReadable()
277{ 277{
278 return true; 278 return true;
279} 279}
280 280
281bool Bu::Client::isWritable() 281bool Bu::Client::isWritable()
282{ 282{
283 return true; 283 return true;
284} 284}
285 285
286bool Bu::Client::isSeekable() 286bool Bu::Client::isSeekable()
287{ 287{
288 return false; 288 return false;
289} 289}
290 290
291bool Bu::Client::isBlocking() 291bool Bu::Client::isBlocking()
292{ 292{
293 return false; 293 return false;
294} 294}
295 295
296void Bu::Client::setBlocking( bool ) 296void Bu::Client::setBlocking( bool )
297{ 297{
298 throw Bu::ExceptionBase(); 298 throw Bu::ExceptionBase();
299} 299}
300 300
301void Bu::Client::setSize( Bu::size ) 301void Bu::Client::setSize( Bu::size )
302{ 302{
303 throw Bu::ExceptionBase(); 303 throw Bu::ExceptionBase();
304} 304}
305 305
306Bu::size Bu::Client::getSize() const 306Bu::size Bu::Client::getSize() const
307{ 307{
308 return 0; 308 return 0;
309} 309}
310 310
311Bu::size Bu::Client::getBlockSize() const 311Bu::size Bu::Client::getBlockSize() const
312{ 312{
313 return pSocket->getBlockSize(); 313 return pSocket->getBlockSize();
314} 314}
315 315
316Bu::String Bu::Client::getLocation() const 316Bu::String Bu::Client::getLocation() const
317{ 317{
318 return pSocket->getLocation(); 318 return pSocket->getLocation();
319} 319}
320 320