summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-06-27 04:08:33 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-06-27 04:08:33 +0200
commit86c1806046dea0bf7c2525d0aa591cdae9b3d330 (patch)
treeab3091e3f2201489383dc212a2b3b10f93dc5796 /src/Core
parentf5377412a89b2a7f422decd771dc8de49a5498fc (diff)
downloadmad-86c1806046dea0bf7c2525d0aa591cdae9b3d330.tar
mad-86c1806046dea0bf7c2525d0aa591cdae9b3d330.zip
Aufwendigere Verarbeitung des Pollings, jetzt auch im Test-Client
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/ConnectionManager.cpp33
-rw-r--r--src/Core/ConnectionManager.h2
2 files changed, 29 insertions, 6 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index fe9f639..ba78a98 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -32,17 +32,26 @@ void ConnectionManager::refreshPollfds() {
// TODO: refreshPollfds()
pollfds.clear();
+ pollfdMap.clear();
for(std::list<Net::Listener*>::iterator listener = listeners.begin(); listener != listeners.end(); ++listener) {
std::vector<struct pollfd> fds = (*listener)->getPollfds();
- pollfds.insert(pollfds.end(), fds.begin(), fds.end());
+
+ for(std::vector<struct pollfd>::iterator fd = fds.begin(); fd != fds.end(); ++fd) {
+ pollfds.push_back(*fd);
+ pollfdMap.insert(std::make_pair(fd->fd, &pollfds.back().revents));
+ }
}
- for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end(); ++con)
+ for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end(); ++con) {
pollfds.push_back((*con)->getPollfd());
+ pollfdMap.insert(std::make_pair(pollfds.back().fd, &pollfds.back().revents));
+ }
- for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con)
+ for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con) {
pollfds.push_back((*con)->getPollfd());
+ pollfdMap.insert(std::make_pair(pollfds.back().fd, &pollfds.back().revents));
+ }
}
void ConnectionManager::daemonReceiveHandler(const Net::Connection *connection, const Net::Packet &packet) {
@@ -96,7 +105,13 @@ void ConnectionManager::run() {
for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end();) {
if((*con)->isConnected()) {
- (*con)->sendReceive();
+ std::map<int,const short*>::iterator events = pollfdMap.find((*con)->getSocket());
+
+ if(events != pollfdMap.end())
+ (*con)->sendReceive(*events->second);
+ else
+ (*con)->sendReceive();
+
++con;
}
else {
@@ -107,7 +122,13 @@ void ConnectionManager::run() {
for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end();) {
if((*con)->isConnected()) {
- (*con)->sendReceive();
+ std::map<int,const short*>::iterator events = pollfdMap.find((*con)->getSocket());
+
+ if(events != pollfdMap.end())
+ (*con)->sendReceive(*events->second);
+ else
+ (*con)->sendReceive();
+
++con;
}
else {
@@ -119,7 +140,7 @@ void ConnectionManager::run() {
for(std::list<Net::Listener*>::iterator listener = listeners.begin(); listener != listeners.end(); ++listener) {
Net::ServerConnection *con;
- while((con = (*listener)->getConnection()) != 0) {
+ while((con = (*listener)->getConnection(pollfdMap)) != 0) {
if(con->isDaemonConnection()) {
daemonConnections.push_back(con);
con->signalReceive().connect(sigc::mem_fun(this, &ConnectionManager::daemonReceiveHandler));
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index b68919c..b252910 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -22,6 +22,7 @@
#include <list>
#include <vector>
+#include <map>
#include <poll.h>
namespace Mad {
@@ -47,6 +48,7 @@ class ConnectionManager {
std::list<Net::ServerConnection*> clientConnections;
std::vector<struct pollfd> pollfds;
+ std::map<int,const short*> pollfdMap;
void refreshPollfds();