diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-06-27 19:34:09 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-06-27 19:34:09 +0200 |
commit | d1306a1710cda4acb9a0138347cdb43943271b9c (patch) | |
tree | 50544a31e47670b257be804648c6d714750cee12 /src/Core | |
parent | b143406a05a1698df5b88b0d4298362a9c8c080b (diff) | |
download | mad-d1306a1710cda4acb9a0138347cdb43943271b9c.tar mad-d1306a1710cda4acb9a0138347cdb43943271b9c.zip |
Verbindungen geregelt trennen... hoffentlich...
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/ConnectionManager.cpp | 49 | ||||
-rw-r--r-- | src/Core/ConnectionManager.h | 3 |
2 files changed, 23 insertions, 29 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index b338f62..5ff5e29 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -29,8 +29,6 @@ namespace Mad { namespace Core { void ConnectionManager::refreshPollfds() { - // TODO: refreshPollfds() - pollfds.clear(); pollfdMap.clear(); @@ -54,31 +52,26 @@ void ConnectionManager::refreshPollfds() { } } -void ConnectionManager::daemonReceiveHandler(const Net::Connection *connection, const Net::Packet &packet) { - std::cout << "Received daemon packet:" << std::endl; - std::cout << " Type: " << packet.getType() << std::endl; - std::cout << " Request ID: 0x" << std::hex << std::uppercase << packet.getRequestId() << std::dec << std::endl; - std::cout << " Length: " << packet.getLength() << std::endl; - - for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end(); ++con) { - if(*con == connection) { - (*con)->disconnect(); +void ConnectionManager::receiveHandler(Net::Connection *connection, const Net::Packet &packet) { + switch(packet.getType()) { + case Net::Packet::TYPE_UNKNOWN: break; - } - } -} - -void ConnectionManager::clientReceiveHandler(const Net::Connection *connection, const Net::Packet &packet) { - std::cout << "Received client packet:" << std::endl; - std::cout << " Type: " << packet.getType() << std::endl; - std::cout << " Request ID: 0x" << std::hex << std::uppercase << packet.getRequestId() << std::dec << std::endl; - std::cout << " Length: " << packet.getLength() << std::endl; - - for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con) { - if(*con == connection) { - (*con)->disconnect(); + case Net::Packet::TYPE_DEBUG: + std::cout << "Received debug packet." << std::endl; + std::cout << " Request ID: 0x" << std::hex << std::uppercase << packet.getRequestId() << std::dec << std::endl; break; - } + case Net::Packet::TYPE_PING: + connection->send(Net::Packet(Net::Packet::TYPE_PONG, packet.getRequestId(), packet.getData(), packet.getLength())); + break; + case Net::Packet::TYPE_PONG: + // TODO: Pong! + break; + case Net::Packet::TYPE_DISCONNECT_REQ: + connection->send(Net::Packet(Net::Packet::TYPE_DISCONNECT_REP, packet.getRequestId())); + connection->disconnect(); + break; + case Net::Packet::TYPE_DISCONNECT_REP: + connection->disconnect(); } } @@ -117,6 +110,7 @@ void ConnectionManager::run() { ++con; } else { + std::cout << "A daemon connection was dropped." << std::endl; delete *con; daemonConnections.erase(con++); } @@ -134,6 +128,7 @@ void ConnectionManager::run() { ++con; } else { + std::cout << "A client connection was dropped." << std::endl; delete *con; clientConnections.erase(con++); } @@ -145,11 +140,11 @@ void ConnectionManager::run() { while((con = (*listener)->getConnection(pollfdMap)) != 0) { if(con->isDaemonConnection()) { daemonConnections.push_back(con); - con->signalReceive().connect(sigc::mem_fun(this, &ConnectionManager::daemonReceiveHandler)); + con->signalReceive().connect(sigc::mem_fun(this, &ConnectionManager::receiveHandler)); } else { clientConnections.push_back(con); - con->signalReceive().connect(sigc::mem_fun(this, &ConnectionManager::clientReceiveHandler)); + con->signalReceive().connect(sigc::mem_fun(this, &ConnectionManager::receiveHandler)); } } } diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h index cbfc812..608ec27 100644 --- a/src/Core/ConnectionManager.h +++ b/src/Core/ConnectionManager.h @@ -52,8 +52,7 @@ class ConnectionManager { void refreshPollfds(); - void daemonReceiveHandler(const Net::Connection *connection, const Net::Packet &packet); - void clientReceiveHandler(const Net::Connection *connection, const Net::Packet &packet); + void receiveHandler(Net::Connection *connection, const Net::Packet &packet); public: ConnectionManager(); |