summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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