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
// -----------------------------------------------------------------------------
GeneralServer::~GeneralServer() {
for (auto& task : _listenTasks) {
delete task;
}
}
GeneralServer::~GeneralServer() {}
// -----------------------------------------------------------------------------
// --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));
task->start();
@ -114,7 +110,6 @@ bool GeneralServer::openEndpoint(Endpoint* endpoint) {
return false;
}
_listenTasks.emplace_back(task.get());
task.release();
_listenTasks.emplace_back(std::move(task));
return true;
}

View File

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

View File

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