aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-10-21 13:49:34 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-10-21 13:49:34 +0200
commit1e1e4e0bbb9734e902e51339ebb8c274c2082e08 (patch)
treefd8998e9800ff464df450b71057a9590ae8e8199 /src
parentf0a2053c2b44298a8cf1aacbafb29870ed521aa0 (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;