aboutsummaryrefslogtreecommitdiff
path: root/src/DirectConnection.cpp
diff options
context:
space:
mode:
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;