summaryrefslogtreecommitdiffstats
path: root/src/Net
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-01 23:03:29 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-01 23:03:29 +0200
commitdcf66f3cc133bf600190b844ab9c0da764e5e82b (patch)
treee3d30777ae7751841cba3bb2aee524cb5438fb9a /src/Net
parenta77d2d1e08e4e2e8dfb5e4fc326f6c8fe315a898 (diff)
downloadmad-dcf66f3cc133bf600190b844ab9c0da764e5e82b.tar
mad-dcf66f3cc133bf600190b844ab9c0da764e5e82b.zip
?berarbeitung der Request-Klasse begonnen
Diffstat (limited to 'src/Net')
-rw-r--r--src/Net/Connection.cpp8
-rw-r--r--src/Net/Connection.h12
-rw-r--r--src/Net/Listener.cpp5
-rw-r--r--src/Net/Listener.h5
-rw-r--r--src/Net/Signals/Signal0.h9
-rw-r--r--src/Net/Signals/Signal1.h12
-rw-r--r--src/Net/Signals/Signal2.h12
-rw-r--r--src/Net/Signals/SignalBase.h10
8 files changed, 41 insertions, 32 deletions
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp
index 1ff9926..b7580d5 100644
--- a/src/Net/Connection.cpp
+++ b/src/Net/Connection.cpp
@@ -55,7 +55,7 @@ void Connection::handleHandshake(const boost::system::error_code& error) {
received = 0;
}
- ThreadManager::get()->pushWork(boost::bind(&Signals::Signal0<void>::emit, &connectedSignal));
+ ThreadManager::get()->pushWork(boost::bind(&Signals::Signal0::emit, &connectedSignal));
enterReceiveLoop();
}
@@ -69,7 +69,7 @@ void Connection::handleShutdown(const boost::system::error_code& error) {
_setState(DISCONNECTED);
- ThreadManager::get()->pushWork(boost::bind(&Signals::Signal0<void>::emit, &disconnectedSignal));
+ ThreadManager::get()->pushWork(boost::bind(&Signals::Signal0::emit, &disconnectedSignal));
}
void Connection::enterReceiveLoop() {
@@ -91,7 +91,7 @@ void Connection::handleHeaderReceive(const std::vector<boost::uint8_t> &data) {
}
if(header.length == 0) {
- ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1<void, const Packet&>::emit, &receiveSignal, Packet(ntohs(header.requestId))));
+ ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1<const Packet&>::emit, &receiveSignal, Packet(ntohs(header.requestId))));
enterReceiveLoop();
}
@@ -105,7 +105,7 @@ void Connection::handleDataReceive(const std::vector<boost::uint8_t> &data) {
boost::upgrade_lock<boost::shared_mutex> lock(connectionLock);
Packet packet(ntohs(header.requestId), data.data(), ntohs(header.length));
- ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1<void, const Packet&>::emit, &receiveSignal, packet));
+ ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1<const Packet&>::emit, &receiveSignal, packet));
}
enterReceiveLoop();
diff --git a/src/Net/Connection.h b/src/Net/Connection.h
index cda8bfe..3938140 100644
--- a/src/Net/Connection.h
+++ b/src/Net/Connection.h
@@ -70,9 +70,9 @@ class Connection : boost::noncopyable {
Packet::Data header;
- Signals::Signal1<void, const Packet&> receiveSignal;
- Signals::Signal0<void> connectedSignal;
- Signals::Signal0<void> disconnectedSignal;
+ Signals::Signal1<const Packet&> receiveSignal;
+ Signals::Signal0 connectedSignal;
+ Signals::Signal0 disconnectedSignal;
bool receiving;
unsigned long sending;
@@ -171,21 +171,21 @@ class Connection : boost::noncopyable {
bool send(const Packet &packet);
- Signals::Connection connectSignalReceive(const Signals::Signal1<void, const Packet&>::slot_type &slot) {
+ Signals::Connection connectSignalReceive(const Signals::Signal1<const Packet&>::slot_type &slot) {
return receiveSignal.connect(slot);
}
void disconnectSignalReceive(const Signals::Connection &connection) {
receiveSignal.disconnect(connection);
}
- Signals::Connection connectSignalConnected(const Signals::Signal0<void>::slot_type &slot) {
+ Signals::Connection connectSignalConnected(const Signals::Signal0::slot_type &slot) {
return connectedSignal.connect(slot);
}
void disconnectSignalConnected(const Signals::Connection &connection) {
connectedSignal.disconnect(connection);
}
- Signals::Connection connectSignalDisconnected(const Signals::Signal0<void>::slot_type &slot) {
+ Signals::Connection connectSignalDisconnected(const Signals::Signal0::slot_type &slot) {
return disconnectedSignal.connect(slot);
}
void disconnectSignalDisconnected(const Signals::Connection &connection) {
diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp
index 6da2762..1188ba3 100644
--- a/src/Net/Listener.cpp
+++ b/src/Net/Listener.cpp
@@ -20,6 +20,7 @@
#include "Listener.h"
#include <Common/Logger.h>
+#include <Net/ThreadManager.h>
#include <cerrno>
#include <cstring>
@@ -52,6 +53,10 @@ void Listener::handleAccept(const boost::system::error_code &error, boost::share
}
void Listener::handleConnect(boost::shared_ptr<Connection> con) {
+ Net::ThreadManager::get()->pushWork(boost::bind(&Listener::doHandleConnect, this, con));
+}
+
+void Listener::doHandleConnect(boost::shared_ptr<Connection> con) {
{
boost::lock_guard<boost::mutex> lock(mutex);
std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection, Signals::Connection> >::iterator it = connections.find(con);
diff --git a/src/Net/Listener.h b/src/Net/Listener.h
index ec0cd22..2f45ea6 100644
--- a/src/Net/Listener.h
+++ b/src/Net/Listener.h
@@ -40,11 +40,12 @@ class Listener : boost::noncopyable {
std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection, Signals::Connection> > connections;
- Signals::Signal1<void, boost::shared_ptr<Connection> > signal;
+ Signals::Signal1<boost::shared_ptr<Connection> > signal;
void handleAccept(const boost::system::error_code &error, boost::shared_ptr<Connection> con);
void handleConnect(boost::shared_ptr<Connection> con);
+ void doHandleConnect(boost::shared_ptr<Connection> con);
void handleDisconnect(boost::shared_ptr<Connection> con);
public:
@@ -52,7 +53,7 @@ class Listener : boost::noncopyable {
const boost::asio::ip::tcp::endpoint &address0 = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 6666)) throw(Exception);
virtual ~Listener();
- Signals::Connection connectSignalNewConnection(const Signals::Signal1<void, boost::shared_ptr<Connection> >::slot_type &slot) {
+ Signals::Connection connectSignalNewConnection(const Signals::Signal1<boost::shared_ptr<Connection> >::slot_type &slot) {
return signal.connect(slot);
}
void disconnectSignalNewConnection(const Signals::Connection &connection) {
diff --git a/src/Net/Signals/Signal0.h b/src/Net/Signals/Signal0.h
index 32859ab..c468135 100644
--- a/src/Net/Signals/Signal0.h
+++ b/src/Net/Signals/Signal0.h
@@ -26,13 +26,12 @@ namespace Mad {
namespace Net {
namespace Signals {
-template <typename R>
-class Signal0 : public SignalBase<boost::signal0<R>, boost::function0<R> > {
+class Signal0 : public SignalBase<boost::signal0<void>, boost::function0<void> > {
public:
- R emit() {
- boost::lock_guard<boost::recursive_mutex> lock(SignalBase<boost::signal0<R>, boost::function0<R> >::mutex);
+ void emit() {
+ boost::lock_guard<boost::mutex> lock(mutex);
- return SignalBase<boost::signal0<R>, boost::function0<R> >::signal();
+ signal();
}
};
diff --git a/src/Net/Signals/Signal1.h b/src/Net/Signals/Signal1.h
index 78eaa47..b9649be 100644
--- a/src/Net/Signals/Signal1.h
+++ b/src/Net/Signals/Signal1.h
@@ -20,17 +20,19 @@
#ifndef MAD_NET_SIGNALS_SIGNAL1_H_
#define MAD_NET_SIGNALS_SIGNAL1_H_
+#include "SignalBase.h"
+
namespace Mad {
namespace Net {
namespace Signals {
-template <typename R, typename T1>
-class Signal1 : public SignalBase<boost::signal1<R, T1>, boost::function1<R, T1> > {
+template <typename T1>
+class Signal1 : public SignalBase<boost::signal1<void, T1>, boost::function1<void, T1> > {
public:
- R emit(T1 arg1) {
- boost::lock_guard<boost::recursive_mutex> lock(SignalBase<boost::signal1<R, T1>, boost::function1<R, T1> >::mutex);
+ void emit(T1 arg1) {
+ boost::lock_guard<boost::mutex> lock(SignalBase<boost::signal1<void, T1>, boost::function1<void, T1> >::mutex);
- return SignalBase<boost::signal1<R, T1>, boost::function1<R, T1> >::signal(arg1);
+ SignalBase<boost::signal1<void, T1>, boost::function1<void, T1> >::signal(arg1);
}
};
diff --git a/src/Net/Signals/Signal2.h b/src/Net/Signals/Signal2.h
index afa528e..374a239 100644
--- a/src/Net/Signals/Signal2.h
+++ b/src/Net/Signals/Signal2.h
@@ -20,17 +20,19 @@
#ifndef MAD_NET_SIGNALS_SIGNAL2_H_
#define MAD_NET_SIGNALS_SIGNAL2_H_
+#include "SignalBase.h"
+
namespace Mad {
namespace Net {
namespace Signals {
-template <typename R, typename T1, typename T2>
-class Signal2 : public SignalBase<boost::signal2<R, T1, T2>, boost::function2<R, T1, T2> > {
+template <typename T1, typename T2>
+class Signal2 : public SignalBase<boost::signal2<void, T1, T2>, boost::function2<void, T1, T2> > {
public:
- R emit(T1 arg1, T2 arg2) {
- boost::lock_guard<boost::recursive_mutex> lock(SignalBase<boost::signal2<R, T1, T2>, boost::function2<R, T1, T2> >::mutex);
+ void emit(T1 arg1, T2 arg2) {
+ boost::lock_guard<boost::mutex> lock(SignalBase<boost::signal2<void, T1, T2>, boost::function2<void, T1, T2> >::mutex);
- return SignalBase<boost::signal2<R, T1, T2>, boost::function2<R, T1, T2> >::signal(arg1, arg2);
+ SignalBase<boost::signal2<void, T1, T2>, boost::function2<void, T1, T2> >::signal(arg1, arg2);
}
};
diff --git a/src/Net/Signals/SignalBase.h b/src/Net/Signals/SignalBase.h
index fc5f2c6..9e2de62 100644
--- a/src/Net/Signals/SignalBase.h
+++ b/src/Net/Signals/SignalBase.h
@@ -25,7 +25,7 @@
#include <set>
#include <boost/signals.hpp>
#include <boost/thread/locks.hpp>
-#include <boost/thread/recursive_mutex.hpp>
+#include <boost/thread/mutex.hpp>
namespace Mad {
namespace Net {
@@ -40,19 +40,19 @@ class SignalBase : private boost::noncopyable {
typedef SignalType signal_type;
std::set<boost::signals::connection> connections;
- boost::recursive_mutex mutex;
+ boost::mutex mutex;
signal_type signal;
SignalBase() {}
~SignalBase() {
// Wait for other threads
- boost::lock_guard<boost::recursive_mutex> lock(mutex);
+ boost::lock_guard<boost::mutex> lock(mutex);
}
public:
Connection connect(const slot_type &slot) {
- boost::lock_guard<boost::recursive_mutex> lock(mutex);
+ boost::lock_guard<boost::mutex> lock(mutex);
boost::signals::connection con(signal.connect(slot));
@@ -61,7 +61,7 @@ class SignalBase : private boost::noncopyable {
}
void disconnect(const Connection &connection) {
- boost::lock_guard<boost::recursive_mutex> lock(mutex);
+ boost::lock_guard<boost::mutex> lock(mutex);
std::set<boost::signals::connection>::iterator it = connections.find(connection.connection);