1
0
Fork 0

re-enable shared_from_this

This commit is contained in:
jsteemann 2017-05-08 22:06:03 +02:00
parent 6d80a77005
commit fc0170f2a8
3 changed files with 8 additions and 12 deletions

View File

@ -46,11 +46,7 @@ using namespace arangodb::rest;
// --SECTION-- constructors and destructors // --SECTION-- constructors and destructors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
GeneralServer::~GeneralServer() { GeneralServer::~GeneralServer() {}
for (auto& task : _listenTasks) {
delete task;
}
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- public methods // --SECTION-- public methods
@ -106,7 +102,7 @@ bool GeneralServer::openEndpoint(Endpoint* endpoint) {
} }
} }
std::unique_ptr<ListenTask> task(new GeneralListenTask( std::shared_ptr<ListenTask> task(new GeneralListenTask(
SchedulerFeature::SCHEDULER->eventLoop(), this, endpoint, protocolType)); SchedulerFeature::SCHEDULER->eventLoop(), this, endpoint, protocolType));
task->start(); task->start();
@ -114,7 +110,6 @@ bool GeneralServer::openEndpoint(Endpoint* endpoint) {
return false; return false;
} }
_listenTasks.emplace_back(task.get()); _listenTasks.emplace_back(std::move(task));
task.release();
return true; return true;
} }

View File

@ -56,7 +56,7 @@ class GeneralServer {
bool openEndpoint(Endpoint* endpoint); bool openEndpoint(Endpoint* endpoint);
private: private:
std::vector<ListenTask*> _listenTasks; std::vector<std::shared_ptr<ListenTask>> _listenTasks;
EndpointList const* _endpointList = nullptr; EndpointList const* _endpointList = nullptr;
}; };
} }

View File

@ -63,8 +63,9 @@ void ListenTask::start() {
TRI_ASSERT(_bound); TRI_ASSERT(_bound);
// auto self = shared_from_this(); auto self = shared_from_this();
_handler = [this](boost::system::error_code const& ec) {
_handler = [this, self](boost::system::error_code const& ec) {
// copy the shared_ptr so nobody can delete the Acceptor while the // copy the shared_ptr so nobody can delete the Acceptor while the
// callback is running // callback is running
std::shared_ptr<Acceptor> acceptorCopy(_acceptor); std::shared_ptr<Acceptor> acceptorCopy(_acceptor);