aboutsummaryrefslogtreecommitdiff
path: root/src/DirectConnection.cpp
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-10-19 23:01:52 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-10-19 23:03:20 +0200
commit54254462e432dcc6ef2bb306a9ee773d21314d19 (patch)
tree3334799426ba0186829de1bbffe0500a64331c31 /src/DirectConnection.cpp
parent3565289c19974ca874f87429cc74a87558249c8e (diff)
Retry put for 30 sec to wait for peer connections
Diffstat (limited to 'src/DirectConnection.cpp')
-rw-r--r--src/DirectConnection.cpp45
1 files changed, 9 insertions, 36 deletions
diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp
index 8034c50..010b8af 100644
--- a/src/DirectConnection.cpp
+++ b/src/DirectConnection.cpp
@@ -82,46 +82,19 @@ namespace sibs
if(rendezvous || bind)
{
- if(reuseAddr)
+ Ipv4 myAddr = addressToBind;
+ for(int i = 0; i < 2000; ++i)
{
- /*
- if(UDT::bind(socket, (sockaddr*)&addressToBind.address, sizeof(addressToBind.address)) == UDT::ERROR)
+ if(UDT::bind(udtSocket, (sockaddr*)&myAddr.address, sizeof(myAddr.address)) == UDT::ERROR)
{
- std::string errMsg = "UDT: Failed to bind, error: ";
- errMsg += UDT::getlasterror_desc();
- throw SocketCreateException(errMsg);
+ port = (u16)generateRandomNumber(2000, 32000);
+ Log::warn("DirectConnections::createSocket: failed to bind socket to port %d, trying port %d. Fail reason: %s", myAddr.getPort(), port, UDT::getlasterror_desc());
+ myAddr.address.sin_port = htons(port);
}
- */
- Ipv4 myAddr = addressToBind;
- for(int i = 0; i < 2000; ++i)
- {
- if(UDT::bind(udtSocket, (sockaddr*)&myAddr.address, sizeof(myAddr.address)) == UDT::ERROR)
- {
- u16 newPort = (u16)generateRandomNumber(2000, 32000);
- Log::warn("DirectConnections: failed to bind socket to port %d, trying port %d. Fail reason: %s", port, newPort, UDT::getlasterror_desc());
- port = newPort;
- myAddr.address.sin_port = htons(port);
- }
- else
- return socket;
- }
- throw SocketCreateException("UDT: Failed to bind after 2000 tries");
- }
- else
- {
- Ipv4 myAddr = addressToBind;
- for(int i = 0; i < 2000; ++i)
- {
- if(UDT::bind(udtSocket, (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
+ return socket;
}
+ throw SocketCreateException("UDT: Failed to bind after 2000 tries");
}
return socket;