From 3c974a33de1e91d9274734b250c40b7295ecbe93 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Wed, 27 Feb 2013 14:03:45 +0000 Subject: [PATCH] network stuff --- include/Utils/Network/Server.h | 5 ++++- src/Utils/Network/Network.cpp | 13 +++++++++++++ src/Utils/Network/Server.cpp | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/Utils/Network/Server.h b/include/Utils/Network/Server.h index 13641e4..c446308 100644 --- a/include/Utils/Network/Server.h +++ b/include/Utils/Network/Server.h @@ -82,6 +82,8 @@ public: void SendPropertyTree(boost::property_tree::ptree pTree); + void DisconnectSlots(); + }; @@ -111,10 +113,11 @@ public: void StartAccept(); void HandleAccept(boost::shared_ptr user, const boost::system::error_code& error); + void DeleteUser(boost::shared_ptr user); //Need to generalize this boost::signal)> OnUserAuthorizedSignal; - //boost::signal OnUserDisconnectedSignal; + boost::signal)> OnUserDisconnectedSignal; }; diff --git a/src/Utils/Network/Network.cpp b/src/Utils/Network/Network.cpp index 0e54548..44ad742 100644 --- a/src/Utils/Network/Network.cpp +++ b/src/Utils/Network/Network.cpp @@ -254,7 +254,20 @@ void TClientSocket::Close() ClientDataReader->DataReadSignalMap.Clear(); + std::shared_ptr authorization = boost::get>(Authorization); + + authorization->AuthorizedSignal.disconnect_all_slots(); + authorization->SaveLoginPasswordSignal.disconnect_all_slots(); + authorization->ErrorSignal.disconnect_all_slots(); + + OnDisconnectedSignal(); + + OnAddressNotResolvedSignal.disconnect_all_slots(); + OnConnectedSignal.disconnect_all_slots(); + OnAutorizedSignal.disconnect_all_slots(); + OnDisconnectedSignal.disconnect_all_slots(); + } } diff --git a/src/Utils/Network/Server.cpp b/src/Utils/Network/Server.cpp index e6b4752..fb4cfb9 100644 --- a/src/Utils/Network/Server.cpp +++ b/src/Utils/Network/Server.cpp @@ -60,11 +60,14 @@ namespace SE TConnectedUser::~TConnectedUser() { + } void TConnectedUser::HandleAllowed(std::string login) { UserDataReader = boost::shared_ptr(new TDataReader(Socket)); + + UserDataReader->ErrorSignal.connect(boost::bind(&TServerSocket::DeleteUser, &Server, shared_from_this())); Login = login; @@ -78,6 +81,19 @@ namespace SE SE::SendPropertyTree(Server.IoService, Socket, pTree); } + void TConnectedUser::DisconnectSlots() + { + UserDataReader->DataReadSignalMap.Clear(); + UserDataReader->ErrorSignal.disconnect_all_slots(); + + std::shared_ptr authorizator = boost::get>(Autorizator); + + authorizator->ErrorSignal.disconnect_all_slots(); + authorizator->AllowedSignal.disconnect_all_slots(); + authorizator->DeniedSignal.disconnect_all_slots(); + + } + @@ -131,8 +147,11 @@ namespace SE UserArr.push_back(user); - boost::get>(user->Autorizator)->AllowedSignal.connect(boost::bind(&TConnectedUser::HandleAllowed, user, _1)); - + std::shared_ptr authorizator = boost::get>(user->Autorizator); + + authorizator->AllowedSignal.connect(boost::bind(&TConnectedUser::HandleAllowed, user, _1)); + authorizator->ErrorSignal.connect(boost::bind(&TServerSocket::DeleteUser, this, user)); + boost::get>(user->Autorizator)->StartListen(); } @@ -140,5 +159,16 @@ namespace SE StartAccept(); } + void TServerSocket::DeleteUser(boost::shared_ptr user) + { + std::vector>::iterator i = std::find(UserArr.begin(), UserArr.end(), user); + + user->DisconnectSlots(); + + OnUserDisconnectedSignal(user); + + UserArr.erase(i); + } + } //namspace SE \ No newline at end of file