summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-02 22:50:28 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-02 22:50:28 +0200
commitf79a215fce13d86a495b6741aae0827ccce43757 (patch)
treeb7a6f61a6ab45cff81e1d7aedb248be56ad2ed7a /src
parent95f2a6b40f5e9dc27be6609d3f7018b3342c4182 (diff)
downloadmad-f79a215fce13d86a495b6741aae0827ccce43757.tar
mad-f79a215fce13d86a495b6741aae0827ccce43757.zip
Net-Namespace auf die neue Signal-Implementierung umgebaut
Diffstat (limited to 'src')
-rw-r--r--src/Common/Connection.cpp4
-rw-r--r--src/Common/Connection.h2
-rw-r--r--src/Net/Connection.cpp11
-rw-r--r--src/Net/Connection.h18
-rw-r--r--src/Net/Listener.cpp13
-rw-r--r--src/Net/Listener.h9
6 files changed, 25 insertions, 32 deletions
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<Net::Packet> 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<Net::Packet> 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 <Common/Logger.h>
@@ -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<boost::uint8_t> &data) {
}
if(header.length == 0) {
- ThreadManager::get()->pushWork(boost::bind(&Signals::Signal1<const Packet&>::emit, &receiveSignal, Packet(ntohs(header.requestId))));
+ receiveSignal.emit(boost::shared_ptr<Packet>(new Packet(ntohs(header.requestId))));
enterReceiveLoop();
}
@@ -104,8 +103,8 @@ 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<const Packet&>::emit, &receiveSignal, packet));
+ Packet packet();
+ receiveSignal.emit(boost::shared_ptr<Packet>(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<const Packet&> receiveSignal;
- Signals::Signal0 connectedSignal;
- Signals::Signal0 disconnectedSignal;
+ Signals::Signal21<boost::shared_ptr<Packet> > 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<const Packet&>::slot_type &slot) {
+ Signals::Connection2 connectSignalReceive(const Signals::Signal21<boost::shared_ptr<Packet> >::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 <Common/Logger.h>
-#include <Net/ThreadManager.h>
#include <cerrno>
#include <cstring>
@@ -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<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);
+ std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection2, Signals::Connection2> >::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<boost::shared_ptr<Connection>,std::pair<Signals::Connection, Signals::Connection> >::iterator con = connections.begin(); con != connections.end(); ++con) {
+ for(std::map<boost::shared_ptr<Connection>,std::pair<Signals::Connection2, Signals::Connection2> >::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<boost::shared_ptr<Connection>, std::pair<Signals::Connection, Signals::Connection> > connections;
+ std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection2, Signals::Connection2> > connections;
- Signals::Signal1<boost::shared_ptr<Connection> > signal;
+ Signals::Signal21<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:
@@ -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<boost::shared_ptr<Connection> >::slot_type &slot) {
+ Signals::Connection2 connectSignalNewConnection(const Signals::Signal21<boost::shared_ptr<Connection> >::slot_type &slot) {
return signal.connect(slot);
}
- void disconnectSignalNewConnection(const Signals::Connection &connection) {
+ void disconnectSignalNewConnection(const Signals::Connection2 &connection) {
signal.disconnect(connection);
}
};