diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-10-10 16:10:57 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-10-10 16:10:57 +0200 |
commit | 0ce519e355b3b2f271439aeac0064db11a06c77b (patch) | |
tree | 23bcff84bc7c860791ef191c49e0999aef15987a /src | |
parent | 969b9f5e5d8a727e5d5588b3385967045f511e5e (diff) | |
download | mad-0ce519e355b3b2f271439aeac0064db11a06c77b.tar mad-0ce519e355b3b2f271439aeac0064db11a06c77b.zip |
Interrupt-Funktion implementiert
Diffstat (limited to 'src')
-rw-r--r-- | src/Net/Connection.cpp | 1 | ||||
-rw-r--r-- | src/Net/FdManager.cpp | 28 | ||||
-rw-r--r-- | src/Net/FdManager.h | 7 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index 72f9848..5454dcf 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -238,7 +238,6 @@ bool Connection::rawSend(const uint8_t *data, unsigned long length) { transS.push(trans); updateEvents(); - doSend(); // TODO !!! return true; } diff --git a/src/Net/FdManager.cpp b/src/Net/FdManager.cpp index aab634d..f58a32e 100644 --- a/src/Net/FdManager.cpp +++ b/src/Net/FdManager.cpp @@ -19,6 +19,10 @@ #include "FdManager.h" #include <signal.h> +#include <unistd.h> +#include <sys/fcntl.h> + +#include <sigc++/hide.h> namespace Mad { @@ -28,12 +32,22 @@ FdManager FdManager::fdManager; FdManager::FdManager() { - // TODO Auto-generated constructor stub + pipe(interruptPipe); + + int flags = fcntl(interruptPipe[0], F_GETFL, 0); + fcntl(interruptPipe[0], F_SETFL, flags | O_NONBLOCK); + flags = fcntl(interruptPipe[1], F_GETFL, 0); + fcntl(interruptPipe[1], F_SETFL, flags | O_NONBLOCK); + + registerFd(interruptPipe[0], sigc::hide(sigc::mem_fun(this, &FdManager::readInterrupt)), POLLIN); } FdManager::~FdManager() { - // TODO Auto-generated destructor stub + unregisterFd(interruptPipe[0]); + + close(interruptPipe[0]); + close(interruptPipe[1]); } @@ -73,8 +87,16 @@ short FdManager::getFdEvents(int fd) const { return pollfd->second.events; } +void FdManager::readInterrupt() { + char buf[20]; + + while(read(interruptPipe[0], buf, sizeof(buf)) > 0) {} +} + void FdManager::interrupt() { - // TODO Implement this. + char buf = 0; + + write(interruptPipe[1], &buf, sizeof(buf)); } void FdManager::run() { diff --git a/src/Net/FdManager.h b/src/Net/FdManager.h index f6a528f..1308a79 100644 --- a/src/Net/FdManager.h +++ b/src/Net/FdManager.h @@ -34,6 +34,11 @@ class FdManager { std::map<int, struct pollfd> pollfds; std::map<int, sigc::slot<void, short> > handlers; + int interruptPipe[2]; + + void readInterrupt(); + void interrupt(); + FdManager(); public: @@ -47,8 +52,6 @@ class FdManager { bool setFdEvents(int fd, short events); short getFdEvents(int fd) const; - void interrupt(); - void run(); }; |