summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-06-12 22:08:16 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-06-12 22:08:16 +0200
commit09e0fc185219e9e625baf096a68a221be55e0284 (patch)
treeca9f6cb1d54de72b50879a0a86378bdaf29e36d0 /src
parentd2969d6f715949521e49a9b99c947ada86b1b49f (diff)
downloadmad-09e0fc185219e9e625baf096a68a221be55e0284.tar
mad-09e0fc185219e9e625baf096a68a221be55e0284.zip
Signalisiere empfangende Pakete.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in2
-rw-r--r--src/Net/Connection.cpp4
-rw-r--r--src/Net/Connection.h5
-rw-r--r--src/Net/Makefile.in2
-rw-r--r--src/mad-core.cpp9
5 files changed, 20 insertions, 2 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 738f494..362222e 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -189,6 +189,8 @@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
+sigc_CFLAGS = @sigc_CFLAGS@
+sigc_LIBS = @sigc_LIBS@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp
index 49b51b4..298eb3e 100644
--- a/src/Net/Connection.cpp
+++ b/src/Net/Connection.cpp
@@ -74,7 +74,7 @@ bool Connection::recieve() {
continue;
if(!header.length) {
- Packet packet(header.type, header.requestId);
+ signal(this, Packet(header.type, header.requestId));
return true;
}
@@ -96,7 +96,7 @@ bool Connection::recieve() {
if(read < header.length+sizeof(Packet::Data))
continue;
- Packet packet(header.type, header.requestId, data, header.length);
+ signal(this, Packet(header.type, header.requestId, data, header.length));
delete [] data;
data = 0;
diff --git a/src/Net/Connection.h b/src/Net/Connection.h
index 80b721f..f48ef20 100644
--- a/src/Net/Connection.h
+++ b/src/Net/Connection.h
@@ -21,6 +21,7 @@
#define MAD_NET_CONNECTION_H_
#include <gnutls/gnutls.h>
+#include <sigc++/signal.h>
#include "Packet.h"
namespace Mad {
@@ -36,6 +37,8 @@ class Connection {
unsigned long read;
+ sigc::signal<void,const Connection*,const Packet&> signal;
+
protected:
virtual gnutls_session_t& getSession() = 0;
@@ -51,6 +54,8 @@ class Connection {
bool send(const Packet &packet);
bool recieve();
+ sigc::signal<void,const Connection*,const Packet&> signalRecieve() const {return signal;}
+
static void init() {
gnutls_global_init();
}
diff --git a/src/Net/Makefile.in b/src/Net/Makefile.in
index 4e7923a..83b718d 100644
--- a/src/Net/Makefile.in
+++ b/src/Net/Makefile.in
@@ -173,6 +173,8 @@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
+sigc_CFLAGS = @sigc_CFLAGS@
+sigc_LIBS = @sigc_LIBS@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
diff --git a/src/mad-core.cpp b/src/mad-core.cpp
index 0c1630b..219621f 100644
--- a/src/mad-core.cpp
+++ b/src/mad-core.cpp
@@ -21,11 +21,20 @@
#include "Net/IPAddress.h"
#include <iostream>
+void recieveHandler(const Mad::Net::Connection*, const Mad::Net::Packet &packet) {
+ std::cout << "Recieved packet:" << std::endl;
+ std::cout << " Type: " << packet.getType() << std::endl;
+ std::cout << " Request ID: " << packet.getRequestId() << std::endl;
+ std::cout << " Length: " << packet.getLength() << std::endl;
+}
+
int main() {
Mad::Net::Connection::init();
Mad::Net::ServerConnection connection;
+ connection.signalRecieve().connect(sigc::ptr_fun(recieveHandler));
+
connection.loadDHParams("dh.pem");
connection.listen(Mad::Net::IPAddress("0.0.0.0", 6666));