#include <Acceptor.h>
Collaboration diagram for gadget::Acceptor:

Public Member Functions | |
| Acceptor (AbstractNetworkManager *network) | |
| Construct an empty TCP/IP acceptor. | |
| virtual | ~Acceptor () |
| Deconstruct object and release memory. | |
| bool | startListening (const int &listen_port, bool accept_anonymous) |
| Start the listening thread on the given port. | |
| void | shutdown () |
| Stop the listen thread. | |
Definition at line 44 of file Acceptor.h.
| gadget::Acceptor::Acceptor | ( | AbstractNetworkManager * | network | ) |
| gadget::Acceptor::~Acceptor | ( | ) | [virtual] |
Deconstruct object and release memory.
Definition at line 53 of file Acceptor.cpp.
References shutdown().
00054 { 00055 shutdown(); 00056 }
| bool gadget::Acceptor::startListening | ( | const int & | listen_port, | |
| bool | accept_anonymous | |||
| ) |
Start the listening thread on the given port.
Definition at line 58 of file Acceptor.cpp.
References gadgetDBG_NET_MGR().
00059 { 00060 mAcceptAnonymous = accept_anonymous; 00061 00062 // If we haven't already started the listening thread 00063 if ( mAcceptThread == NULL ) 00064 { 00065 // If the listen port is valid 00066 if ( listen_port > 0 ) 00067 { 00068 mListenAddr.setPort( listen_port ); 00069 00070 vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) 00071 << clrOutBOLD( clrMAGENTA, "[Acceptor]" ) 00072 << "Starting the listening thread...\n" << vprDEBUG_FLUSH; 00073 00074 // Start a thread to monitor port 00075 vpr::ThreadMemberFunctor<Acceptor>* memberFunctor = 00076 new vpr::ThreadMemberFunctor<Acceptor>( this, &Acceptor::acceptLoop, NULL ); 00077 00078 mAcceptThread = new vpr::Thread( memberFunctor ); 00079 vprASSERT( mAcceptThread->valid() ); 00080 return true; 00081 } 00082 else 00083 { 00084 vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) 00085 << clrOutBOLD( clrMAGENTA, "[Acceptor]" ) 00086 << "startListening() Can NOT listen on port: " 00087 << listen_port << "\n" << vprDEBUG_FLUSH; 00088 return false; 00089 } 00090 } 00091 else 00092 { 00093 vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) 00094 << clrOutBOLD( clrMAGENTA,"[Acceptor]" ) 00095 << "startListening() Listening thread already active." 00096 << std::endl << vprDEBUG_FLUSH; 00097 return false; 00098 } 00099 }
| void gadget::Acceptor::shutdown | ( | ) |
Stop the listen thread.
Definition at line 328 of file Acceptor.cpp.
Referenced by ~Acceptor().
00329 { 00330 // Kill thread used to listen for incoming 00331 // connection requests 00332 00333 // TODO: Make this actually shutdown the Accepting thread, this will require 00334 // non blocking accept calls. 00335 if ( mAcceptThread ) 00336 { 00337 mAcceptThread->kill(); 00338 mAcceptThread = NULL; 00339 } 00340 }
1.5.1