From dcf66f3cc133bf600190b844ab9c0da764e5e82b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 1 Jun 2009 23:03:29 +0200 Subject: ?berarbeitung der Request-Klasse begonnen --- src/Net/Connection.cpp | 8 ++++---- src/Net/Connection.h | 12 ++++++------ src/Net/Listener.cpp | 5 +++++ src/Net/Listener.h | 5 +++-- src/Net/Signals/Signal0.h | 9 ++++----- src/Net/Signals/Signal1.h | 12 +++++++----- src/Net/Signals/Signal2.h | 12 +++++++----- src/Net/Signals/SignalBase.h | 10 +++++----- 8 files changed, 41 insertions(+), 32 deletions(-) (limited to 'src/Net') 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::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::emit, &disconnectedSignal)); + ThreadManager::get()->pushWork(boost::bind(&Signals::Signal0::emit, &disconnectedSignal)); } void Connection::enterReceiveLoop() { @@ -91,7 +91,7 @@ void Connection::handleHeaderReceive(const std::vector &data) { } if(header.length == 0) { - ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1::emit, &receiveSignal, Packet(ntohs(header.requestId)))); + ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1::emit, &receiveSignal, Packet(ntohs(header.requestId)))); enterReceiveLoop(); } @@ -105,7 +105,7 @@ void Connection::handleDataReceive(const std::vector &data) { boost::upgrade_lock lock(connectionLock); Packet packet(ntohs(header.requestId), data.data(), ntohs(header.length)); - ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1::emit, &receiveSignal, packet)); + ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1::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 receiveSignal; - Signals::Signal0 connectedSignal; - Signals::Signal0 disconnectedSignal; + Signals::Signal1 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::slot_type &slot) { + Signals::Connection connectSignalReceive(const Signals::Signal1::slot_type &slot) { return receiveSignal.connect(slot); } void disconnectSignalReceive(const Signals::Connection &connection) { receiveSignal.disconnect(connection); } - Signals::Connection connectSignalConnected(const Signals::Signal0::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::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 +#include #include #include @@ -52,6 +53,10 @@ void Listener::handleAccept(const boost::system::error_code &error, boost::share } void Listener::handleConnect(boost::shared_ptr con) { + Net::ThreadManager::get()->pushWork(boost::bind(&Listener::doHandleConnect, this, con)); +} + +void Listener::doHandleConnect(boost::shared_ptr con) { { boost::lock_guard lock(mutex); std::map, std::pair >::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, std::pair > connections; - Signals::Signal1 > signal; + Signals::Signal1 > signal; void handleAccept(const boost::system::error_code &error, boost::shared_ptr con); void handleConnect(boost::shared_ptr con); + void doHandleConnect(boost::shared_ptr con); void handleDisconnect(boost::shared_ptr 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 >::slot_type &slot) { + Signals::Connection connectSignalNewConnection(const Signals::Signal1 >::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 -class Signal0 : public SignalBase, boost::function0 > { +class Signal0 : public SignalBase, boost::function0 > { public: - R emit() { - boost::lock_guard lock(SignalBase, boost::function0 >::mutex); + void emit() { + boost::lock_guard lock(mutex); - return SignalBase, boost::function0 >::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 -class Signal1 : public SignalBase, boost::function1 > { +template +class Signal1 : public SignalBase, boost::function1 > { public: - R emit(T1 arg1) { - boost::lock_guard lock(SignalBase, boost::function1 >::mutex); + void emit(T1 arg1) { + boost::lock_guard lock(SignalBase, boost::function1 >::mutex); - return SignalBase, boost::function1 >::signal(arg1); + SignalBase, boost::function1 >::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 -class Signal2 : public SignalBase, boost::function2 > { +template +class Signal2 : public SignalBase, boost::function2 > { public: - R emit(T1 arg1, T2 arg2) { - boost::lock_guard lock(SignalBase, boost::function2 >::mutex); + void emit(T1 arg1, T2 arg2) { + boost::lock_guard lock(SignalBase, boost::function2 >::mutex); - return SignalBase, boost::function2 >::signal(arg1, arg2); + SignalBase, boost::function2 >::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 #include #include -#include +#include namespace Mad { namespace Net { @@ -40,19 +40,19 @@ class SignalBase : private boost::noncopyable { typedef SignalType signal_type; std::set connections; - boost::recursive_mutex mutex; + boost::mutex mutex; signal_type signal; SignalBase() {} ~SignalBase() { // Wait for other threads - boost::lock_guard lock(mutex); + boost::lock_guard lock(mutex); } public: Connection connect(const slot_type &slot) { - boost::lock_guard lock(mutex); + boost::lock_guard 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 lock(mutex); + boost::lock_guard lock(mutex); std::set::iterator it = connections.find(connection.connection); -- cgit v1.2.3