Skip to content
Snippets Groups Projects
Unverified Commit 5dc034b6 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

peerconnection: avoid blocking connect


Change-Id: Ibbf85bd1449785feee76067341c908cbd8dc4ea2
Reviewed-by: default avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent 6a6d9010
Branches
No related tags found
No related merge requests found
...@@ -241,10 +241,13 @@ TcpSocketEndpoint::~TcpSocketEndpoint() ...@@ -241,10 +241,13 @@ TcpSocketEndpoint::~TcpSocketEndpoint()
} }
void void
TcpSocketEndpoint::connect() TcpSocketEndpoint::connect(const std::chrono::steady_clock::duration& timeout)
{ {
// Blocking method int ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count();
if (::connect(sock_, addr_, addr_.getLength()) < 0) setsockopt(sock_, SOL_SOCKET, SO_RCVTIMEO, (const char *)&ms, sizeof(ms));
setsockopt(sock_, SOL_SOCKET, SO_SNDTIMEO, (const char *)&ms, sizeof(ms));
if ((::connect(sock_, addr_, addr_.getLength())) < 0)
throw std::system_error(errno, std::generic_category()); throw std::system_error(errno, std::generic_category());
} }
......
...@@ -126,7 +126,7 @@ public: ...@@ -126,7 +126,7 @@ public:
throw std::logic_error("TcpSocketEndpoint::setOnRecv not implemented"); throw std::logic_error("TcpSocketEndpoint::setOnRecv not implemented");
} }
void connect(); void connect(const std::chrono::steady_clock::duration& timeout = {});
private: private:
const IpAddr addr_; const IpAddr addr_;
......
...@@ -348,7 +348,18 @@ private: ...@@ -348,7 +348,18 @@ private:
RING_DBG() << parent_.account << "[CNX] connecting to TURN relay " RING_DBG() << parent_.account << "[CNX] connecting to TURN relay "
<< relay_addr.toString(true, true); << relay_addr.toString(true, true);
peer_ep = std::make_unique<TcpSocketEndpoint>(relay_addr); peer_ep = std::make_unique<TcpSocketEndpoint>(relay_addr);
peer_ep->connect(); // IMPROVE_ME: socket timeout? try {
peer_ep->connect(SOCK_TIMEOUT);
} catch (const std::logic_error& e) {
// In case of a timeout
RING_WARN() << "TcpSocketEndpoint timeout for addr " << relay_addr.toString(true, true) << ": " << e.what();
cancel();
return;
} catch (...) {
RING_WARN() << "TcpSocketEndpoint failure for addr " << relay_addr.toString(true, true);
cancel();
return;
}
break; break;
} catch (std::system_error&) { } catch (std::system_error&) {
RING_DBG() << parent_.account << "[CNX] Failed to connect to TURN relay " RING_DBG() << parent_.account << "[CNX] Failed to connect to TURN relay "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment