diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-10-21 08:52:53 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 22:56:48 +0200 |
commit | 40510daeca17b3db2cad0c9101d8f513df7127d1 (patch) | |
tree | 608232662f9f0c8abbff1af1aa4bfb0ef1a84282 /include/sibs | |
parent | 980312b2a6e96c6d301d30d38922f8a2cc315c92 (diff) |
Fix concurrent connection to the same address
Diffstat (limited to 'include/sibs')
-rw-r--r-- | include/sibs/DirectConnection.hpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/include/sibs/DirectConnection.hpp b/include/sibs/DirectConnection.hpp index 9be55f1..2137fd2 100644 --- a/include/sibs/DirectConnection.hpp +++ b/include/sibs/DirectConnection.hpp @@ -13,6 +13,7 @@ #include "../utils.hpp" #include "Socket.hpp" #include "Message.hpp" +#include <future> namespace sibs { @@ -29,6 +30,13 @@ namespace sibs }; struct DirectConnectionPeer; + + struct PubSubConnectResult + { + std::shared_ptr<DirectConnectionPeer> peer; + PubSubResult result; + std::string resultStr; + }; using PubSubConnectCallback = std::function<void(std::shared_ptr<DirectConnectionPeer> peer, PubSubResult result, const std::string &resultStr)>; using PubSubReceiveDataCallback = std::function<void(std::shared_ptr<DirectConnectionPeer> peer, MessageType messageType, const void *data, const usize size)>; @@ -65,8 +73,6 @@ namespace sibs bool removePeer(int peerSocket); std::vector<std::shared_ptr<DirectConnectionPeer>> getPeers(); - - std::shared_ptr<DirectConnectionPeer> getPeerByAddress(const Ipv4 &address) const; protected: std::unique_ptr<Socket> createSocket(const Ipv4 &addressToBind, bool rendezvous, bool reuseAddr, bool bind = true); private: @@ -82,7 +88,8 @@ namespace sibs std::mutex peersMutex; bool alive; PubSubOnRemoveDisconnectedPeerCallback removeDisconnectedPeerCallback; - Ipv4Map<std::shared_ptr<DirectConnectionPeer>> peerByAddressMap; + Ipv4Map<std::shared_future<PubSubConnectResult>> connectionResults; + std::mutex connectionResultsMutex; }; struct DirectConnectionsUtils |