summaryrefslogtreecommitdiffstats
path: root/src/Net
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/Net
parentf5377412a89b2a7f422decd771dc8de49a5498fc (diff)
downloadmad-86c1806046dea0bf7c2525d0aa591cdae9b3d330.tar
mad-86c1806046dea0bf7c2525d0aa591cdae9b3d330.zip
Aufwendigere Verarbeitung des Pollings, jetzt auch im Test-Client
Diffstat (limited to 'src/Net')
-rw-r--r--src/Net/Connection.h15
-rw-r--r--src/Net/Listener.cpp13
-rw-r--r--src/Net/Listener.h3
3 files changed, 24 insertions, 7 deletions
diff --git a/src/Net/Connection.h b/src/Net/Connection.h
index e147ad2..adb677a 100644
--- a/src/Net/Connection.h
+++ b/src/Net/Connection.h
@@ -136,6 +136,7 @@ class Connection {
}
const IPAddress* getPeer() {return peer;}
+ int getSocket() const {return sock;}
void disconnect();
@@ -148,14 +149,22 @@ class Connection {
return rawSend(reinterpret_cast<const unsigned char*>(packet.getRawData()), packet.getRawDataLength());
}
- void sendReceive() {
+ void sendReceive(short events = POLLIN|POLLOUT) {
+ if(events & POLLHUP || events & POLLERR) {
+ disconnect();
+ return;
+ }
+
if(state == HANDSHAKE) {
doHandshake();
return;
}
- doReceive();
- doSend();
+ if(events & POLLIN)
+ doReceive();
+
+ if(events & POLLOUT)
+ doSend();
}
bool sendQueueEmpty() const {return transS.empty();}
diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp
index 8386389..981b3c7 100644
--- a/src/Net/Listener.cpp
+++ b/src/Net/Listener.cpp
@@ -90,21 +90,28 @@ std::vector<struct pollfd> Listener::getPollfds() const {
return pollfds;
}
-ServerConnection* Listener::getConnection() {
+ServerConnection* Listener::getConnection(const std::map<int,const short*> &pollfdMap) {
// TODO: Logging
int sd;
struct sockaddr_in sa;
socklen_t addrlen = sizeof(sa);
+
while((sd = accept(sock, reinterpret_cast<struct sockaddr*>(&sa), &addrlen)) >= 0) {
connections.push_back(new ServerConnection(sd, IPAddress(sa), dh_params));
addrlen = sizeof(sa);
}
- for(std::list<ServerConnection*>::iterator con = connections.begin(); con != connections.end(); ++con)
- (*con)->sendReceive();
+ for(std::list<ServerConnection*>::iterator con = connections.begin(); con != connections.end(); ++con) {
+ std::map<int,const short*>::const_iterator events = pollfdMap.find((*con)->getSocket());
+
+ if(events != pollfdMap.end())
+ (*con)->sendReceive(*events->second);
+ else
+ (*con)->sendReceive();
+ }
for(std::list<ServerConnection*>::iterator con = connections.begin(); con != connections.end();) {
if(!(*con)->isConnected()) {
diff --git a/src/Net/Listener.h b/src/Net/Listener.h
index 9952268..30fde63 100644
--- a/src/Net/Listener.h
+++ b/src/Net/Listener.h
@@ -26,6 +26,7 @@
#include <poll.h>
#include <list>
#include <vector>
+#include <map>
namespace Mad {
namespace Net {
@@ -51,7 +52,7 @@ class Listener {
std::vector<struct pollfd> getPollfds() const;
- ServerConnection* getConnection();
+ ServerConnection* getConnection(const std::map<int,const short*> &pollfdMap);
};
}