diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-06-18 22:03:02 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-06-18 22:03:02 +0200 |
commit | 7234fe326d16d6bf9f4374a09ddc6ef790e6723f (patch) | |
tree | 437d4c40eeb1e9b34b369e4b82064a1572c7dac9 /src/Net | |
parent | bf561f8226e97f4ace4f04bddf198175e91ee7f0 (diff) | |
download | mad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.tar mad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.zip |
Globale Variablen durch Application-Klasse ersetzt
Diffstat (limited to 'src/Net')
-rw-r--r-- | src/Net/ClientConnection.h | 6 | ||||
-rw-r--r-- | src/Net/Connection.cpp | 10 | ||||
-rw-r--r-- | src/Net/Connection.h | 7 | ||||
-rw-r--r-- | src/Net/Listener.cpp | 14 | ||||
-rw-r--r-- | src/Net/Listener.h | 6 |
5 files changed, 23 insertions, 20 deletions
diff --git a/src/Net/ClientConnection.h b/src/Net/ClientConnection.h index dcb6906..02cd0c7 100644 --- a/src/Net/ClientConnection.h +++ b/src/Net/ClientConnection.h @@ -36,9 +36,9 @@ class ClientConnection : private boost::base_from_member<boost::asio::ssl::conte void handleConnect(const boost::system::error_code& error); public: - ClientConnection() - : boost::base_from_member<boost::asio::ssl::context>(boost::ref(Core::ThreadManager::get()->getIOService()), boost::asio::ssl::context::sslv23), - Connection(member) + ClientConnection(Core::Application *application) + : boost::base_from_member<boost::asio::ssl::context>(boost::ref(application->getIOService()), boost::asio::ssl::context::sslv23), + Connection(application, member) { member.set_verify_mode(boost::asio::ssl::context::verify_none); } diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index 81f4c64..fabbd12 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -19,7 +19,7 @@ #include "Connection.h" -#include <Core/Logger.h> +#include <Core/Application.h> #include <cstring> #include <boost/bind.hpp> @@ -35,7 +35,7 @@ Connection::~Connection() { void Connection::handleHandshake(const boost::system::error_code& error) { if(error) { - Core::Logger::logf("Error: %s", error.message().c_str()); + application->logf("Error: %s", error.message().c_str()); // TODO Error handling doDisconnect(); @@ -61,7 +61,7 @@ void Connection::handleShutdown(const boost::system::error_code& error) { boost::lock_guard<boost::shared_mutex> lock(connectionLock); if(error) { - Core::Logger::logf(Core::Logger::VERBOSE, "Shutdown error: %s", error.message().c_str()); + application->logf(Core::LoggerBase::VERBOSE, "Shutdown error: %s", error.message().c_str()); } _setState(DISCONNECTED); @@ -110,7 +110,7 @@ void Connection::handleDataReceive(const std::vector<boost::uint8_t> &data) { void Connection::handleRead(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t length, const boost::function1<void, const std::vector<boost::uint8_t>& > ¬ify) { if(error || (bytes_transferred+received) < length) { - Core::Logger::logf(Core::Logger::VERBOSE, "Read error: %s", error.message().c_str()); + application->logf(Core::LoggerBase::VERBOSE, "Read error: %s", error.message().c_str()); // TODO Error doDisconnect(); @@ -183,7 +183,7 @@ void Connection::handleWrite(const boost::system::error_code& error, std::size_t } if(error) { - Core::Logger::logf(Core::Logger::VERBOSE, "Write error: %s", error.message().c_str()); + application->logf(Core::LoggerBase::VERBOSE, "Write error: %s", error.message().c_str()); // TODO Error doDisconnect(); diff --git a/src/Net/Connection.h b/src/Net/Connection.h index 6323164..0506d13 100644 --- a/src/Net/Connection.h +++ b/src/Net/Connection.h @@ -62,6 +62,8 @@ class Connection : boost::noncopyable { boost::asio::const_buffer buffer; }; + Core::Application *application; + boost::condition_variable_any stateChanged; State state; @@ -115,8 +117,9 @@ class Connection : boost::noncopyable { void doDisconnect(); - Connection(boost::asio::ssl::context &sslContext) : - state(DISCONNECTED), receiveBuffer(1024*1024), socket(Core::ThreadManager::get()->getIOService(), sslContext) {} + Connection(Core::Application *application0, boost::asio::ssl::context &sslContext) : + application(application0), state(DISCONNECTED), receiveBuffer(1024*1024), receiveSignal(application), connectedSignal(application), + disconnectedSignal(application), socket(application->getIOService(), sslContext) {} public: virtual ~Connection(); diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp index 780e862..2bdb189 100644 --- a/src/Net/Listener.cpp +++ b/src/Net/Listener.cpp @@ -19,9 +19,6 @@ #include "Listener.h" -#include <Core/Logger.h> -#include <Core/ThreadManager.h> - #include <cerrno> #include <cstring> #include <fcntl.h> @@ -48,7 +45,7 @@ void Listener::handleAccept(const boost::system::error_code &error, boost::share con->socket.async_handshake(boost::asio::ssl::stream_base::server, boost::bind(&Connection::handleHandshake, con, boost::asio::placeholders::error)); } - con.reset(new Connection(sslContext)); + con.reset(new Connection(application, sslContext)); acceptor.async_accept(con->socket.lowest_layer(), boost::bind(&Listener::handleAccept, this, boost::asio::placeholders::error, con)); } @@ -76,10 +73,11 @@ void Listener::handleDisconnect(boost::shared_ptr<Connection> con) { } -Listener::Listener(const std::string &x905CertFile0, const std::string &x905KeyFile0, +Listener::Listener(Core::Application *application0, const std::string &x905CertFile0, const std::string &x905KeyFile0, const boost::asio::ip::tcp::endpoint &address0) throw(Core::Exception) -: x905CertFile(x905CertFile0), x905KeyFile(x905KeyFile0), address(address0), acceptor(Core::ThreadManager::get()->getIOService(), address), -sslContext(Core::ThreadManager::get()->getIOService(), boost::asio::ssl::context::sslv23) +: application(application0), x905CertFile(x905CertFile0), x905KeyFile(x905KeyFile0), address(address0), +acceptor(application->getIOService(), address), sslContext(application->getIOService(), boost::asio::ssl::context::sslv23), +signal(application) { sslContext.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 @@ -89,7 +87,7 @@ sslContext(Core::ThreadManager::get()->getIOService(), boost::asio::ssl::context - boost::shared_ptr<Connection> con(new Connection(sslContext)); + boost::shared_ptr<Connection> con(new Connection(application, sslContext)); acceptor.async_accept(con->socket.lowest_layer(), boost::bind(&Listener::handleAccept, this, boost::asio::placeholders::error, con)); } diff --git a/src/Net/Listener.h b/src/Net/Listener.h index af0888b..931cd99 100644 --- a/src/Net/Listener.h +++ b/src/Net/Listener.h @@ -29,8 +29,10 @@ namespace Mad { namespace Net { -class Listener : boost::noncopyable { +class Listener : private boost::noncopyable { private: + Core::Application *application; + boost::mutex mutex; std::string x905CertFile, x905KeyFile; @@ -48,7 +50,7 @@ class Listener : boost::noncopyable { void handleDisconnect(boost::shared_ptr<Connection> con); public: - Listener(const std::string &x905CertFile0, const std::string &x905KeyFile0, + Listener(Core::Application *application0, const std::string &x905CertFile0, const std::string &x905KeyFile0, const boost::asio::ip::tcp::endpoint &address0 = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 6666)) throw(Core::Exception); virtual ~Listener(); |