aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-21 13:49:34 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 22:56:48 +0200
commitf96ed2f3195166485875e801cd0d923023a2dd4e (patch)
tree1720e76558c3b92ca127f05502b42fe9f4890ba8 /src
parent4f84a5d325686202bd623ee530d197596ff3f411 (diff)
Async bootstrap connect
Diffstat (limited to 'src')
-rw-r--r--src/BootstrapConnection.cpp19
1 files changed, 19 insertions, 0 deletions
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<std::unique_ptr<BootstrapConnection>> BootstrapConnection::create(const Ipv4 &bootstrapAddress)
+ {
+ std::promise<std::unique_ptr<BootstrapConnection>> connectionPromise;
+ std::future<std::unique_ptr<BootstrapConnection>> connectionFuture = connectionPromise.get_future();
+ std::thread([bootstrapAddress](std::promise<std::unique_ptr<BootstrapConnection>> connectionPromise)
+ {
+ try
+ {
+ BootstrapConnection *connection = new BootstrapConnection(bootstrapAddress);
+ connectionPromise.set_value(std::unique_ptr<BootstrapConnection>(connection));
+ }
+ catch(...)
+ {
+ connectionPromise.set_exception(std::current_exception());
+ }
+ }, std::move(connectionPromise)).detach();
+ return connectionFuture;
+ }
+
BootstrapConnection::~BootstrapConnection()
{
alive = false;