From 80153a5bb5d3b41101e6bd6755b61fd0e57fadbc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 2 Nov 2006 11:29:19 +0000 Subject: 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. --- src/connectionmanager.cpp | 18 ++++++++++++++++++ src/connectionmanager.h | 2 ++ src/connectionmonitor.h | 4 ++++ src/protocol.cpp | 2 -- src/protocol.h | 4 ++++ 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 ) lActive.erase( l ); continue; } + (*i)->poll(); if( (*i)->hasOutput() ) { (*i)->writeOutput(); @@ -324,6 +325,23 @@ bool ConnectionManager::addConnection( int nSocket ) return true; } +void ConnectionManager::connect( + const char *lpAddress, + int nPort, + int nProtocolPort + ) +{ + Connection *pCon = getInactiveConnection(); + pCon->open( lpAddress, nPort ); + int nSocket = pCon->getSocket(); + FD_SET( nSocket, &fdActive ); + + pMonitor->onNewClientConnection( pCon, nProtocolPort ); + pCon->getProtocol()->onNewClientConnection(); + + lActive.insert( lActive.end(), pCon ); +} + Connection *ConnectionManager::getInactiveConnection() { 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: */ void setConnectionMonitor( ConnectionMonitor *pNewMonitor ); + void connect( const char *lpAddress, int nPort, int nProtocolPort ); + private: /** * 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: * force a shutdown. */ virtual bool onNewConnection( Connection *pCon, int nPort ) = 0; + virtual bool onNewClientConnection( Connection *pCon, int nPort ) + { + return onNewConnection( pCon, nPort ); + }; /** Receives the notification that a connection was closed. *@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() void Protocol::setConnection( Connection *pNewConnection ) { pConnection = pNewConnection; - - onNewConnection(); } Connection *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: */ virtual bool onNewConnection()=0; + virtual void onNewClientConnection(){}; + + virtual void poll(){}; + /** * Sets the Protocol's Connection object. This is rather important, and * handled usually by the ConnectionManager. -- cgit v1.2.3