From fcab8098d6a9a385e0e5edfb26f4abf615da77ca Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 10 Oct 2008 15:04:28 +0200 Subject: FdManager hinzugef?gt und Verbindungsklassen angepasst --- src/Net/Connection.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/Net/Connection.cpp') diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index 03e9f73..72f9848 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -18,6 +18,7 @@ */ #include "Connection.h" +#include "FdManager.h" #include "IPAddress.h" #include #include @@ -67,8 +68,11 @@ void Connection::doHandshake() { int ret = gnutls_handshake(session); if(ret < 0) { - if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) + if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) { + updateEvents(); return; + } + // TODO: Error doDisconnect(); @@ -85,8 +89,10 @@ void Connection::doBye() { int ret = gnutls_bye(session, GNUTLS_SHUT_RDWR); if(ret < 0) { - if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) + if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) { + updateEvents(); return; + } // TODO: Error doDisconnect(); @@ -172,6 +178,8 @@ void Connection::doReceive() { delete [] data; } + + updateEvents(); } bool Connection::rawReceive(unsigned long length, @@ -188,6 +196,8 @@ bool Connection::rawReceive(unsigned long length, transR.transmitted = 0; transR.notify = notify; + updateEvents(); + return true; } @@ -215,6 +225,8 @@ void Connection::doSend() { transS.pop(); } } + + updateEvents(); } bool Connection::rawSend(const uint8_t *data, unsigned long length) { @@ -225,7 +237,8 @@ bool Connection::rawSend(const uint8_t *data, unsigned long length) { std::memcpy(trans.data, data, length); transS.push(trans); - doSend(); + updateEvents(); + doSend(); // TODO !!! return true; } @@ -276,6 +289,8 @@ void Connection::doDisconnect() { if(!isConnected()) return; + FdManager::getFdManager()->unregisterFd(sock); + shutdown(sock, SHUT_RDWR); close(sock); @@ -284,13 +299,13 @@ void Connection::doDisconnect() { state = DISCONNECTED; } -struct pollfd Connection::getPollfd() const { - struct pollfd fd = {sock, (receiveComplete() ? 0 : POLLIN) | (sendQueueEmpty() ? 0 : POLLOUT), 0}; +void Connection::updateEvents() const { + short events = (receiveComplete() ? 0 : POLLIN) | (sendQueueEmpty() ? 0 : POLLOUT); if(state == HANDSHAKE || state == BYE) - fd.events = ((gnutls_record_get_direction(session) == 0) ? POLLIN : POLLOUT); + events = ((gnutls_record_get_direction(session) == 0) ? POLLIN : POLLOUT); - return fd; + FdManager::getFdManager()->setFdEvents(sock, events); } } -- cgit v1.2.3