summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-06-30 04:28:47 +0000
committerMike Buland <eichlan@xagasoft.com>2009-06-30 04:28:47 +0000
commit89df61f21e525c7a36846ce1a960ffba5501cdca (patch)
tree0789e81c229b8f55521ca1c14e01c74165bae99b /src/client.cpp
parent4556c5f625ed143a2334acc26505b658b719b451 (diff)
downloadlibbu++-89df61f21e525c7a36846ce1a960ffba5501cdca.tar.gz
libbu++-89df61f21e525c7a36846ce1a960ffba5501cdca.tar.bz2
libbu++-89df61f21e525c7a36846ce1a960ffba5501cdca.tar.xz
libbu++-89df61f21e525c7a36846ce1a960ffba5501cdca.zip
Bu::Client now gives you the option to add additional filters to the filter
chain on the base stream, which for the moment is a socket. I also demonstrate this in the new rot13 test, with a rot13 filter, and a simple echo protocol.
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 43d1a08..24f9bfb 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -17,18 +17,23 @@
17#define RBS (1024*2) 17#define RBS (1024*2)
18 18
19Bu::Client::Client( Bu::Socket *pSocket, class Bu::ClientLinkFactory *pfLink ) : 19Bu::Client::Client( Bu::Socket *pSocket, class Bu::ClientLinkFactory *pfLink ) :
20 pTopStream( pSocket ),
20 pSocket( pSocket ), 21 pSocket( pSocket ),
21 pProto( NULL ), 22 pProto( NULL ),
22 nRBOffset( 0 ), 23 nRBOffset( 0 ),
23 bWantsDisconnect( false ), 24 bWantsDisconnect( false ),
24 pfLink( pfLink ) 25 pfLink( pfLink )
25{ 26{
27 lFilts.prepend( pSocket );
26} 28}
27 29
28Bu::Client::~Client() 30Bu::Client::~Client()
29{ 31{
30 delete pSocket; 32 for( FilterList::iterator i = lFilts.begin(); i; i++ )
31 pSocket = NULL; 33 {
34 delete *i;
35 }
36 pTopStream = pSocket = NULL;
32} 37}
33 38
34void Bu::Client::processInput() 39void Bu::Client::processInput()
@@ -40,7 +45,7 @@ void Bu::Client::processInput()
40 { 45 {
41 try 46 try
42 { 47 {
43 nRead = pSocket->read( buf, RBS ); 48 nRead = pTopStream->read( buf, RBS );
44 49
45 if( nRead == 0 ) 50 if( nRead == 0 )
46 { 51 {
@@ -50,13 +55,13 @@ void Bu::Client::processInput()
50 { 55 {
51 nTotal += nRead; 56 nTotal += nRead;
52 sReadBuf.append( buf, nRead ); 57 sReadBuf.append( buf, nRead );
53 if( !pSocket->canRead() ) 58 if( !pTopStream->canRead() )
54 break; 59 break;
55 } 60 }
56 } 61 }
57 catch( Bu::SocketException &e ) 62 catch( Bu::SocketException &e )
58 { 63 {
59 pSocket->close(); 64 pTopStream->close();
60 bWantsDisconnect = true; 65 bWantsDisconnect = true;
61 break; 66 break;
62 } 67 }
@@ -64,7 +69,7 @@ void Bu::Client::processInput()
64 69
65 if( nTotal == 0 ) 70 if( nTotal == 0 )
66 { 71 {
67 pSocket->close(); 72 pTopStream->close();
68 bWantsDisconnect = true; 73 bWantsDisconnect = true;
69 } 74 }
70 75
@@ -79,7 +84,7 @@ void Bu::Client::processOutput()
79 if( sWriteBuf.getSize() > 0 ) 84 if( sWriteBuf.getSize() > 0 )
80 { 85 {
81 int nAmnt = (sWriteBuf.getSize()<2048)?(sWriteBuf.getSize()):(2048); 86 int nAmnt = (sWriteBuf.getSize()<2048)?(sWriteBuf.getSize()):(2048);
82 int nReal = pSocket->write( sWriteBuf.getStr(), nAmnt ); 87 int nReal = pTopStream->write( sWriteBuf.getStr(), nAmnt );
83 sWriteBuf.trimFront( nReal ); 88 sWriteBuf.trimFront( nReal );
84 //sWriteBuf.clear(); 89 //sWriteBuf.clear();
85 } 90 }
@@ -113,8 +118,8 @@ Bu::FString &Bu::Client::getOutput()
113 118
114bool Bu::Client::isOpen() 119bool Bu::Client::isOpen()
115{ 120{
116 if( !pSocket ) return false; 121 if( !pTopStream ) return false;
117 return pSocket->isOpen(); 122 return pTopStream->isOpen();
118} 123}
119 124
120void Bu::Client::write( const Bu::FString &sData ) 125void Bu::Client::write( const Bu::FString &sData )
@@ -235,7 +240,7 @@ bool Bu::Client::wantsDisconnect()
235 240
236void Bu::Client::close() 241void Bu::Client::close()
237{ 242{
238 pSocket->close(); 243 pTopStream->close();
239} 244}
240 245
241Bu::ClientLink *Bu::Client::getLink() 246Bu::ClientLink *Bu::Client::getLink()