aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-11-02 11:29:19 +0000
committerMike Buland <eichlan@xagasoft.com>2006-11-02 11:29:19 +0000
commit80153a5bb5d3b41101e6bd6755b61fd0e57fadbc (patch)
tree6a2989723396348d509b63466bf53023f4f82739 /src
parent54ef2750aef0c64df56daff50af7719f85017c33 (diff)
downloadlibbu++-80153a5bb5d3b41101e6bd6755b61fd0e57fadbc.tar.gz
libbu++-80153a5bb5d3b41101e6bd6755b61fd0e57fadbc.tar.bz2
libbu++-80153a5bb5d3b41101e6bd6755b61fd0e57fadbc.tar.xz
libbu++-80153a5bb5d3b41101e6bd6755b61fd0e57fadbc.zip
Added the new features that you need to make the connection manager, protocols,
and the connection monitor work in two-way-mode. Effectively you should be able to write systems that both serve and initiate connections, and only write one protocol.
Diffstat (limited to 'src')
-rw-r--r--src/connectionmanager.cpp18
-rw-r--r--src/connectionmanager.h2
-rw-r--r--src/connectionmonitor.h4
-rw-r--r--src/protocol.cpp2
-rw-r--r--src/protocol.h4
5 files changed, 28 insertions, 2 deletions
diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp
index 3e9f1a8..367b9d7 100644
--- a/src/connectionmanager.cpp
+++ b/src/connectionmanager.cpp
@@ -195,6 +195,7 @@ bool ConnectionManager::scanConnections( int nTimeout, bool bForceTimeout )
195 lActive.erase( l ); 195 lActive.erase( l );
196 continue; 196 continue;
197 } 197 }
198 (*i)->poll();
198 if( (*i)->hasOutput() ) 199 if( (*i)->hasOutput() )
199 { 200 {
200 (*i)->writeOutput(); 201 (*i)->writeOutput();
@@ -324,6 +325,23 @@ bool ConnectionManager::addConnection( int nSocket )
324 return true; 325 return true;
325} 326}
326 327
328void ConnectionManager::connect(
329 const char *lpAddress,
330 int nPort,
331 int nProtocolPort
332 )
333{
334 Connection *pCon = getInactiveConnection();
335 pCon->open( lpAddress, nPort );
336 int nSocket = pCon->getSocket();
337 FD_SET( nSocket, &fdActive );
338
339 pMonitor->onNewClientConnection( pCon, nProtocolPort );
340 pCon->getProtocol()->onNewClientConnection();
341
342 lActive.insert( lActive.end(), pCon );
343}
344
327Connection *ConnectionManager::getInactiveConnection() 345Connection *ConnectionManager::getInactiveConnection()
328{ 346{
329 if( lInactive.empty() ) 347 if( lInactive.empty() )
diff --git a/src/connectionmanager.h b/src/connectionmanager.h
index 85eb7ad..23d059a 100644
--- a/src/connectionmanager.h
+++ b/src/connectionmanager.h
@@ -93,6 +93,8 @@ public:
93 */ 93 */
94 void setConnectionMonitor( ConnectionMonitor *pNewMonitor ); 94 void setConnectionMonitor( ConnectionMonitor *pNewMonitor );
95 95
96 void connect( const char *lpAddress, int nPort, int nProtocolPort );
97
96private: 98private:
97 /** 99 /**
98 * Take care of the work of actually accepting a connection. This will 100 * Take care of the work of actually accepting a connection. This will
diff --git a/src/connectionmonitor.h b/src/connectionmonitor.h
index 01b2cca..9910556 100644
--- a/src/connectionmonitor.h
+++ b/src/connectionmonitor.h
@@ -31,6 +31,10 @@ public:
31 * force a shutdown. 31 * force a shutdown.
32 */ 32 */
33 virtual bool onNewConnection( Connection *pCon, int nPort ) = 0; 33 virtual bool onNewConnection( Connection *pCon, int nPort ) = 0;
34 virtual bool onNewClientConnection( Connection *pCon, int nPort )
35 {
36 return onNewConnection( pCon, nPort );
37 };
34 38
35 /** Receives the notification that a connection was closed. 39 /** Receives the notification that a connection was closed.
36 *@param pCon The connection that was closed. 40 *@param pCon The connection that was closed.
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 70c8a02..78b3ee2 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -12,8 +12,6 @@ Protocol::~Protocol()
12void Protocol::setConnection( Connection *pNewConnection ) 12void Protocol::setConnection( Connection *pNewConnection )
13{ 13{
14 pConnection = pNewConnection; 14 pConnection = pNewConnection;
15
16 onNewConnection();
17} 15}
18 16
19Connection *Protocol::getConnection() 17Connection *Protocol::getConnection()
diff --git a/src/protocol.h b/src/protocol.h
index cd18e37..09e1c98 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -36,6 +36,10 @@ public:
36 */ 36 */
37 virtual bool onNewConnection()=0; 37 virtual bool onNewConnection()=0;
38 38
39 virtual void onNewClientConnection(){};
40
41 virtual void poll(){};
42
39 /** 43 /**
40 * Sets the Protocol's Connection object. This is rather important, and 44 * Sets the Protocol's Connection object. This is rather important, and
41 * handled usually by the ConnectionManager. 45 * handled usually by the ConnectionManager.