summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-18 19:42:34 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-18 19:42:34 +0000
commit8b12972092777af56ae21f65b41f4c40d52c2367 (patch)
tree3ee45c4b69899acb0cdbd013ea8e6ea54bcdc023 /src/client.cpp
parent5292e5831934dc719d1ac06332bd252abe4ac3bc (diff)
downloadlibbu++-8b12972092777af56ae21f65b41f4c40d52c2367.tar.gz
libbu++-8b12972092777af56ae21f65b41f4c40d52c2367.tar.bz2
libbu++-8b12972092777af56ae21f65b41f4c40d52c2367.tar.xz
libbu++-8b12972092777af56ae21f65b41f4c40d52c2367.zip
Added the protocol class. servers work, but don't send data, updated the streams
to include many more state indicators and caps queries, and everything is working better in general.
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp69
1 files changed, 67 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp
index a33cdc3..cf96424 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1,6 +1,16 @@
1#include "client.h" 1#include "bu/client.h"
2#include "bu/socket.h"
3#include <stdlib.h>
4#include <errno.h>
5#include "bu/exceptions.h"
6#include "bu/protocol.h"
2 7
3Bu::Client::Client() 8/** Read buffer size. */
9#define RBS (1024*2)
10
11Bu::Client::Client( Bu::Socket *pSocket ) :
12 pSocket( pSocket ),
13 pProto( NULL )
4{ 14{
5} 15}
6 16
@@ -8,3 +18,58 @@ Bu::Client::~Client()
8{ 18{
9} 19}
10 20
21void Bu::Client::processInput()
22{
23 char buf[RBS];
24 size_t nRead, nTotal=0;
25
26 for(;;)
27 {
28 nRead = pSocket->read( buf, nRead );
29 if( nRead < 0 )
30 {
31 throw Bu::ConnectionException(
32 excodeReadError,
33 "Read error: %s",
34 strerror( errno )
35 );
36 }
37 else if( nRead == 0 )
38 {
39 break;
40 }
41 else
42 {
43 nTotal += nRead;
44 sReadBuf.append( buf, nRead );
45 if( !pSocket->canRead() )
46 break;
47 }
48 }
49
50 if( pProto && nTotal )
51 {
52 pProto->onNewData( this );
53 }
54}
55
56void Bu::Client::setProtocol( Protocol *pProto )
57{
58 this->pProto = pProto;
59}
60
61Bu::Protocol *Bu::Client::getProtocol()
62{
63 return pProto;
64}
65
66void Bu::Client::clearProtocol()
67{
68 pProto = NULL;
69}
70
71Bu::FString &Bu::Client::getInput()
72{
73 return sReadBuf;
74}
75