Core/Bnet: Fixed crash on shutdown happening when there were still players connected

This commit is contained in:
Shauren
2015-04-11 01:55:45 +02:00
parent 4ced9a4480
commit 5659db6f03
6 changed files with 48 additions and 17 deletions

View File

@@ -30,7 +30,7 @@ public:
AsyncAcceptor(boost::asio::io_service& ioService, std::string const& bindIp, uint16 port) :
_acceptor(ioService, tcp::endpoint(boost::asio::ip::address::from_string(bindIp), port)),
_socket(ioService)
_socket(ioService), _closed(false)
{
}
@@ -55,13 +55,24 @@ public:
}
}
AsyncAcceptManaged(mgrHandler);
if (!_closed)
AsyncAcceptManaged(mgrHandler);
});
}
void Close()
{
if (_closed.exchange(true))
return;
boost::system::error_code err;
_acceptor.close(err);
}
private:
tcp::acceptor _acceptor;
tcp::socket _socket;
std::atomic<bool> _closed;
};
template<class T>
@@ -83,7 +94,8 @@ void AsyncAcceptor::AsyncAccept()
}
// lets slap some more this-> on this so we can fix this bug with gcc 4.7.2 throwing internals in yo face
this->AsyncAccept<T>();
if (!_closed)
this->AsyncAccept<T>();
});
}

View File

@@ -147,6 +147,8 @@ protected:
}
TC_LOG_DEBUG("misc", "Network Thread exits");
_newSockets.clear();
_Sockets.clear();
}
private:

View File

@@ -33,8 +33,7 @@ class SocketMgr
public:
virtual ~SocketMgr()
{
delete _acceptor;
delete[] _threads;
ASSERT(!_threads && !_acceptor && !_threadCount, "StopNetwork must be called prior to SocketMgr destruction");
}
virtual bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port)
@@ -69,11 +68,19 @@ public:
virtual void StopNetwork()
{
_acceptor->Close();
if (_threadCount != 0)
for (int32 i = 0; i < _threadCount; ++i)
_threads[i].Stop();
Wait();
delete _acceptor;
_acceptor = nullptr;
delete[] _threads;
_threads = nullptr;
_threadCount = 0;
}
void Wait()