aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-18 22:44:45 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-18 22:44:45 +0000
commit33012c4ef4d39efad4fbc2b19f494f5c860fff51 (patch)
tree8bef67016807893f32b5a4d6aa822c65534500a5 /src
parent6f94639a3f5e20e1c635b2d8676086464d7cba2e (diff)
downloadlibbu++-33012c4ef4d39efad4fbc2b19f494f5c860fff51.tar.gz
libbu++-33012c4ef4d39efad4fbc2b19f494f5c860fff51.tar.bz2
libbu++-33012c4ef4d39efad4fbc2b19f494f5c860fff51.tar.xz
libbu++-33012c4ef4d39efad4fbc2b19f494f5c860fff51.zip
The client/server system now works both ways, in and out, and works as well as
the old one in pretty much every way, and better in most. It's much easier to understand. And the atom class is better.
Diffstat (limited to 'src')
-rw-r--r--src/atom.h2
-rw-r--r--src/client.cpp25
-rw-r--r--src/client.h6
-rw-r--r--src/server.cpp17
-rw-r--r--src/server.h3
5 files changed, 50 insertions, 3 deletions
diff --git a/src/atom.h b/src/atom.h
index 731e08b..f876274 100644
--- a/src/atom.h
+++ b/src/atom.h
@@ -27,7 +27,7 @@ namespace Bu
27 clear(); 27 clear();
28 } 28 }
29 29
30 bool isSet() const 30 bool has() const
31 { 31 {
32 return (pData != NULL); 32 return (pData != NULL);
33 } 33 }
diff --git a/src/client.cpp b/src/client.cpp
index 6d7d81c..0e48285 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -58,6 +58,15 @@ void Bu::Client::processInput()
58 } 58 }
59} 59}
60 60
61void Bu::Client::processOutput()
62{
63 if( sWriteBuf.getSize() > 0 )
64 {
65 pSocket->write( sWriteBuf.getStr(), sWriteBuf.getSize() );
66 sWriteBuf.clear();
67 }
68}
69
61void Bu::Client::setProtocol( Protocol *pProto ) 70void Bu::Client::setProtocol( Protocol *pProto )
62{ 71{
63 this->pProto = pProto; 72 this->pProto = pProto;
@@ -78,3 +87,19 @@ Bu::FString &Bu::Client::getInput()
78 return sReadBuf; 87 return sReadBuf;
79} 88}
80 89
90Bu::FString &Bu::Client::getOutput()
91{
92 return sWriteBuf;
93}
94
95bool Bu::Client::isOpen()
96{
97 if( !pSocket ) return false;
98 return pSocket->isOpen();
99}
100
101void Bu::Client::write( const char *pData, int nBytes )
102{
103 sWriteBuf.append( pData, nBytes );
104}
105
diff --git a/src/client.h b/src/client.h
index 1a189e2..02ba077 100644
--- a/src/client.h
+++ b/src/client.h
@@ -20,17 +20,23 @@ namespace Bu
20 virtual ~Client(); 20 virtual ~Client();
21 21
22 void processInput(); 22 void processInput();
23 void processOutput();
23 24
24 Bu::FString &getInput(); 25 Bu::FString &getInput();
26 Bu::FString &getOutput();
27 void write( const char *pData, int nBytes );
25 28
26 void setProtocol( Protocol *pProto ); 29 void setProtocol( Protocol *pProto );
27 Bu::Protocol *getProtocol(); 30 Bu::Protocol *getProtocol();
28 void clearProtocol(); 31 void clearProtocol();
29 32
33 bool isOpen();
34
30 private: 35 private:
31 Bu::Socket *pSocket; 36 Bu::Socket *pSocket;
32 Bu::Protocol *pProto; 37 Bu::Protocol *pProto;
33 Bu::FString sReadBuf; 38 Bu::FString sReadBuf;
39 Bu::FString sWriteBuf;
34 }; 40 };
35} 41}
36 42
diff --git a/src/server.cpp b/src/server.cpp
index bceeb81..d07a597 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -61,10 +61,25 @@ void Bu::Server::scan()
61 } 61 }
62 else 62 else
63 { 63 {
64 hClients.get( j )->processInput(); 64 Client *pClient = hClients.get( j );
65 pClient->processInput();
66 if( !pClient->isOpen() )
67 {
68 onClosedConnection( pClient );
69 hClients.erase( j );
70 FD_CLR( j, &fdActive );
71 }
65 } 72 }
66 } 73 }
67 } 74 }
75
76 // Now we just try to write all the pending data on all the sockets.
77 // this could be done better eventually, if we care about the socket
78 // wanting to accept writes (using a select).
79 for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ )
80 {
81 (*i)->processOutput();
82 }
68} 83}
69 84
70void Bu::Server::addClient( int nSocket, int nPort ) 85void Bu::Server::addClient( int nSocket, int nPort )
diff --git a/src/server.h b/src/server.h
index 3331d2c..07eef95 100644
--- a/src/server.h
+++ b/src/server.h
@@ -53,7 +53,8 @@ namespace Bu
53 int nTimeoutUSec; 53 int nTimeoutUSec;
54 fd_set fdActive; 54 fd_set fdActive;
55 Hash<int,ServerSocket *> hServers; 55 Hash<int,ServerSocket *> hServers;
56 Hash<int,Client *> hClients; 56 typedef Hash<int,Client *> ClientHash;
57 ClientHash hClients;
57 }; 58 };
58} 59}
59 60