From 1e1e4e0bbb9734e902e51339ebb8c274c2082e08 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Sun, 21 Oct 2018 13:49:34 +0200 Subject: Async bootstrap connect --- src/BootstrapConnection.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/BootstrapConnection.cpp b/src/BootstrapConnection.cpp index f74129b..c70fbc9 100644 --- a/src/BootstrapConnection.cpp +++ b/src/BootstrapConnection.cpp @@ -54,6 +54,25 @@ namespace sibs } } + std::future> BootstrapConnection::create(const Ipv4 &bootstrapAddress) + { + std::promise> connectionPromise; + std::future> connectionFuture = connectionPromise.get_future(); + std::thread([bootstrapAddress](std::promise> connectionPromise) + { + try + { + BootstrapConnection *connection = new BootstrapConnection(bootstrapAddress); + connectionPromise.set_value(std::unique_ptr(connection)); + } + catch(...) + { + connectionPromise.set_exception(std::current_exception()); + } + }, std::move(connectionPromise)).detach(); + return connectionFuture; + } + BootstrapConnection::~BootstrapConnection() { alive = false; -- cgit v1.2.3