aboutsummaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-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