diff options
Diffstat (limited to 'src/Net')
-rw-r--r-- | src/Net/Connection.cpp | 6 | ||||
-rw-r--r-- | src/Net/Connection.h | 5 | ||||
-rw-r--r-- | src/Net/Listener.cpp | 19 | ||||
-rw-r--r-- | src/Net/Listener.h | 4 |
4 files changed, 33 insertions, 1 deletions
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index e7be313..4e3fee4 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -168,5 +168,11 @@ void Connection::disconnect() { state = DISCONNECTED; } +struct pollfd Connection::getPollfd() const { + struct pollfd fd = {sock, (receiveComplete() ? 0 : POLLIN) | (sendQueueEmpty() ? 0 : POLLOUT), 0}; + + return fd; +} + } } diff --git a/src/Net/Connection.h b/src/Net/Connection.h index 0ef3ebf..0880036 100644 --- a/src/Net/Connection.h +++ b/src/Net/Connection.h @@ -23,6 +23,7 @@ #include <queue> #include <gnutls/gnutls.h> #include <sigc++/signal.h> +#include <poll.h> #include "Packet.h" namespace Mad { @@ -125,6 +126,8 @@ class Connection { void disconnect(); + struct pollfd getPollfd() const; + bool send(const Packet &packet) { if(!isConnected() || isConnecting()) return false; @@ -142,7 +145,7 @@ class Connection { doSend(); } - bool sendQueueEmpty() {return transS.empty();} + bool sendQueueEmpty() const {return transS.empty();} sigc::signal<void,const Connection*,const Packet&> signalReceive() const {return signal;} diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp index 3fb2415..8386389 100644 --- a/src/Net/Listener.cpp +++ b/src/Net/Listener.cpp @@ -67,13 +67,32 @@ Listener::Listener(const IPAddress &address0) throw(ConnectionException) } Listener::~Listener() { + for(std::list<ServerConnection*>::iterator con = connections.begin(); con != connections.end(); ++con) { + (*con)->disconnect(); + delete *con; + } + shutdown(sock, SHUT_RDWR); close(sock); gnutls_dh_params_deinit(dh_params); } +std::vector<struct pollfd> Listener::getPollfds() const { + std::vector<struct pollfd> pollfds; + + struct pollfd fd = {sock, POLLIN, 0}; + pollfds.push_back(fd); + + for(std::list<ServerConnection*>::const_iterator con = connections.begin(); con != connections.end(); ++con) + pollfds.push_back((*con)->getPollfd()); + + return pollfds; +} + ServerConnection* Listener::getConnection() { + // TODO: Logging + int sd; struct sockaddr_in sa; socklen_t addrlen = sizeof(sa); diff --git a/src/Net/Listener.h b/src/Net/Listener.h index 5c59a6e..9952268 100644 --- a/src/Net/Listener.h +++ b/src/Net/Listener.h @@ -23,7 +23,9 @@ #include "IPAddress.h" #include "ConnectionException.h" #include <gnutls/gnutls.h> +#include <poll.h> #include <list> +#include <vector> namespace Mad { namespace Net { @@ -47,6 +49,8 @@ class Listener { Listener(const IPAddress &address0) throw(ConnectionException); virtual ~Listener(); + std::vector<struct pollfd> getPollfds() const; + ServerConnection* getConnection(); }; |