aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-10-21 08:52:53 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-10-21 08:52:55 +0200
commite81aea0fc96a2eb44e09d3aa0aad1e7d11878cae (patch)
tree62006080a5747622e83df76eefb7eca230f40a6d /include
parent54254462e432dcc6ef2bb306a9ee773d21314d19 (diff)
Fix concurrent connection to the same address
Diffstat (limited to 'include')
-rw-r--r--include/sibs/DirectConnection.hpp13
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