From 55405854c27417ec33797c9e2b438ce17ac70bf2 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Sun, 14 Oct 2018 04:17:54 +0200 Subject: Add peer to listen callback --- src/DirectConnection.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/DirectConnection.cpp') diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index 540f7cb..71c7f1f 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -74,12 +74,26 @@ namespace sibs { if(reuseAddr) { + /* if(UDT::bind(socket, (sockaddr*)&addressToBind.address, sizeof(addressToBind.address)) == UDT::ERROR) { std::string errMsg = "UDT: Failed to bind, error: "; errMsg += UDT::getlasterror_desc(); throw SocketCreateException(errMsg); } + */ + Ipv4 myAddr = addressToBind; + for(int i = 0; i < 2000; ++i) + { + if(UDT::bind(socket, (sockaddr*)&myAddr.address, sizeof(myAddr.address)) == UDT::ERROR) + { + port = (u16)generateRandomNumber(2000, 32000); + myAddr.address.sin_port = htons(port); + } + else + return socket; + } + throw SocketCreateException("UDT: Failed to bind after 2000 tries"); } else { -- cgit v1.2.3