From 40510daeca17b3db2cad0c9101d8f513df7127d1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 21 Oct 2018 08:52:53 +0200 Subject: Fix concurrent connection to the same address --- include/sibs/DirectConnection.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'include') 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 namespace sibs { @@ -29,6 +30,13 @@ namespace sibs }; struct DirectConnectionPeer; + + struct PubSubConnectResult + { + std::shared_ptr peer; + PubSubResult result; + std::string resultStr; + }; using PubSubConnectCallback = std::function peer, PubSubResult result, const std::string &resultStr)>; using PubSubReceiveDataCallback = std::function peer, MessageType messageType, const void *data, const usize size)>; @@ -65,8 +73,6 @@ namespace sibs bool removePeer(int peerSocket); std::vector> getPeers(); - - std::shared_ptr getPeerByAddress(const Ipv4 &address) const; protected: std::unique_ptr 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> peerByAddressMap; + Ipv4Map> connectionResults; + std::mutex connectionResultsMutex; }; struct DirectConnectionsUtils -- cgit v1.2.3