summaryrefslogtreecommitdiffstats
path: root/src/Net/Connection.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-10-10 15:04:28 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-10-10 15:04:28 +0200
commitfcab8098d6a9a385e0e5edfb26f4abf615da77ca (patch)
tree7ae3ff0d47bab59a409ccebb036e339894493b80 /src/Net/Connection.cpp
parent535a6e799ee98e745c85c655c5db3279fd25c1bc (diff)
downloadmad-fcab8098d6a9a385e0e5edfb26f4abf615da77ca.tar
mad-fcab8098d6a9a385e0e5edfb26f4abf615da77ca.zip
FdManager hinzugef?gt und Verbindungsklassen angepasst
Diffstat (limited to 'src/Net/Connection.cpp')
-rw-r--r--src/Net/Connection.cpp29
1 files changed, 22 insertions, 7 deletions
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 <cstring>
#include <sys/socket.h>
@@ -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);
}
}