From 30f0cb9154306938250bd77ce2f0a9471065732a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 7 Jul 2008 01:12:19 +0200 Subject: Benutze *-Listener, wenn keiner konfiguriert ist --- src/Core/ConnectionManager.cpp | 14 ++++++++++++-- src/Net/IPAddress.h | 7 +++++++ src/Net/Listener.h | 14 +++++++------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 48d9c17..b9903c9 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -51,14 +51,24 @@ void ConnectionManager::refreshPollfds() { } ConnectionManager::ConnectionManager(const std::vector &listenerAddresses) { - for(std::vector::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { + if(listenerAddresses.empty()) { try { - listeners.push_back(new Net::Listener(*address)); + listeners.push_back(new Net::Listener()); } catch(Net::Exception &e) { // TODO: Log error } } + else { + for(std::vector::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { + try { + listeners.push_back(new Net::Listener(*address)); + } + catch(Net::Exception &e) { + // TODO: Log error + } + } + } refreshPollfds(); } diff --git a/src/Net/IPAddress.h b/src/Net/IPAddress.h index bbaae44..b0fad45 100644 --- a/src/Net/IPAddress.h +++ b/src/Net/IPAddress.h @@ -35,6 +35,13 @@ class IPAddress { struct sockaddr_in sa; public: + // TODO Default port + IPAddress(unsigned short port0 = 6666) : addr(INADDR_ANY), port(port0) { + sa.sin_family = AF_INET; + sa.sin_port = htons(port); + sa.sin_addr.s_addr = INADDR_ANY; + } + IPAddress(unsigned int address, unsigned short port0) : addr(address), port(port0) { sa.sin_family = AF_INET; sa.sin_port = htons(port); diff --git a/src/Net/Listener.h b/src/Net/Listener.h index 30fde63..81260ed 100644 --- a/src/Net/Listener.h +++ b/src/Net/Listener.h @@ -37,21 +37,21 @@ class Listener { private: IPAddress address; int sock; - + gnutls_dh_params_t dh_params; - + std::list connections; - + // Prevent shallow copy Listener(const Listener &o); Listener& operator=(const Listener &o); - + public: - Listener(const IPAddress &address0) throw(ConnectionException); + Listener(const IPAddress &address0 = IPAddress()) throw(ConnectionException); virtual ~Listener(); - + std::vector getPollfds() const; - + ServerConnection* getConnection(const std::map &pollfdMap); }; -- cgit v1.2.3