From f79a215fce13d86a495b6741aae0827ccce43757 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 2 Jun 2009 22:50:28 +0200 Subject: Net-Namespace auf die neue Signal-Implementierung umgebaut --- src/Common/Connection.cpp | 4 ++-- src/Common/Connection.h | 2 +- src/Net/Connection.cpp | 11 +++++------ src/Net/Connection.h | 18 +++++++++--------- src/Net/Listener.cpp | 13 ++++--------- src/Net/Listener.h | 9 ++++----- 6 files changed, 25 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/Common/Connection.cpp b/src/Common/Connection.cpp index 5b2eee9..db962ea 100644 --- a/src/Common/Connection.cpp +++ b/src/Common/Connection.cpp @@ -23,8 +23,8 @@ namespace Mad { namespace Common { -void Connection::receive(const Net::Packet &packet) { - signalReceive.emit(XmlPacket(packet), packet.getRequestId()); +void Connection::receive(boost::shared_ptr packet) { + signalReceive.emit(XmlPacket(*packet), packet->getRequestId()); } bool Connection::sendPacket(const XmlPacket &packet, uint16_t requestId) { diff --git a/src/Common/Connection.h b/src/Common/Connection.h index 0dd2f2e..b794a88 100644 --- a/src/Common/Connection.h +++ b/src/Common/Connection.h @@ -44,7 +44,7 @@ class Connection : private boost::noncopyable { protected: Connection() : authenticated(0) {} - void receive(const Net::Packet &packet); + void receive(boost::shared_ptr packet); virtual bool send(const Net::Packet &packet) = 0; diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index b7580d5..d9ff994 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -18,7 +18,6 @@ */ #include "Connection.h" -#include "ThreadManager.h" #include @@ -55,7 +54,7 @@ void Connection::handleHandshake(const boost::system::error_code& error) { received = 0; } - ThreadManager::get()->pushWork(boost::bind(&Signals::Signal0::emit, &connectedSignal)); + connectedSignal.emit(); enterReceiveLoop(); } @@ -69,7 +68,7 @@ void Connection::handleShutdown(const boost::system::error_code& error) { _setState(DISCONNECTED); - ThreadManager::get()->pushWork(boost::bind(&Signals::Signal0::emit, &disconnectedSignal)); + disconnectedSignal.emit(); } void Connection::enterReceiveLoop() { @@ -91,7 +90,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)))); + receiveSignal.emit(boost::shared_ptr(new Packet(ntohs(header.requestId)))); enterReceiveLoop(); } @@ -104,8 +103,8 @@ 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)); + Packet packet(); + receiveSignal.emit(boost::shared_ptr(new Packet(ntohs(header.requestId), data.data(), ntohs(header.length)))); } enterReceiveLoop(); diff --git a/src/Net/Connection.h b/src/Net/Connection.h index 3938140..505dcea 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::Signal21 > receiveSignal; + Signals::Signal20 connectedSignal; + Signals::Signal20 disconnectedSignal; bool receiving; unsigned long sending; @@ -171,24 +171,24 @@ class Connection : boost::noncopyable { bool send(const Packet &packet); - Signals::Connection connectSignalReceive(const Signals::Signal1::slot_type &slot) { + Signals::Connection2 connectSignalReceive(const Signals::Signal21 >::slot_type &slot) { return receiveSignal.connect(slot); } - void disconnectSignalReceive(const Signals::Connection &connection) { + void disconnectSignalReceive(const Signals::Connection2 &connection) { receiveSignal.disconnect(connection); } - Signals::Connection connectSignalConnected(const Signals::Signal0::slot_type &slot) { + Signals::Connection2 connectSignalConnected(const Signals::Signal20::slot_type &slot) { return connectedSignal.connect(slot); } - void disconnectSignalConnected(const Signals::Connection &connection) { + void disconnectSignalConnected(const Signals::Connection2 &connection) { connectedSignal.disconnect(connection); } - Signals::Connection connectSignalDisconnected(const Signals::Signal0::slot_type &slot) { + Signals::Connection2 connectSignalDisconnected(const Signals::Signal20::slot_type &slot) { return disconnectedSignal.connect(slot); } - void disconnectSignalDisconnected(const Signals::Connection &connection) { + void disconnectSignalDisconnected(const Signals::Connection2 &connection) { disconnectedSignal.disconnect(connection); } }; diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp index 1188ba3..b9779ec 100644 --- a/src/Net/Listener.cpp +++ b/src/Net/Listener.cpp @@ -20,7 +20,6 @@ #include "Listener.h" #include -#include #include #include @@ -40,8 +39,8 @@ void Listener::handleAccept(const boost::system::error_code &error, boost::share con->_setState(Connection::CONNECT); - Signals::Connection con1 = con->connectSignalConnected(boost::bind(&Listener::handleConnect, this, con)); - Signals::Connection con2 = con->connectSignalDisconnected(boost::bind(&Listener::handleDisconnect, this, con)); + Signals::Connection2 con1 = con->connectSignalConnected(boost::bind(&Listener::handleConnect, this, con)); + Signals::Connection2 con2 = con->connectSignalDisconnected(boost::bind(&Listener::handleDisconnect, this, con)); connections.insert(std::make_pair(con, std::make_pair(con1, con2))); @@ -53,13 +52,9 @@ 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); + std::map, std::pair >::iterator it = connections.find(con); if(it == connections.end()) return; @@ -98,7 +93,7 @@ sslContext(Connection::ioService, boost::asio::ssl::context::sslv23) } Listener::~Listener() { - for(std::map,std::pair >::iterator con = connections.begin(); con != connections.end(); ++con) { + for(std::map,std::pair >::iterator con = connections.begin(); con != connections.end(); ++con) { con->first->disconnect(); // TODO wait... } diff --git a/src/Net/Listener.h b/src/Net/Listener.h index 2f45ea6..600fcf9 100644 --- a/src/Net/Listener.h +++ b/src/Net/Listener.h @@ -38,14 +38,13 @@ class Listener : boost::noncopyable { boost::asio::ip::tcp::acceptor acceptor; boost::asio::ssl::context sslContext; - std::map, std::pair > connections; + std::map, std::pair > connections; - Signals::Signal1 > signal; + Signals::Signal21 > 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: @@ -53,10 +52,10 @@ 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::Connection2 connectSignalNewConnection(const Signals::Signal21 >::slot_type &slot) { return signal.connect(slot); } - void disconnectSignalNewConnection(const Signals::Connection &connection) { + void disconnectSignalNewConnection(const Signals::Connection2 &connection) { signal.disconnect(connection); } }; -- cgit v1.2.3