diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2017-09-18 18:45:51 -0400 |
---|---|---|
committer | Cory Fields <cory-nospam-@coryfields.com> | 2017-12-12 15:25:25 -0500 |
commit | 1729c29dedc64d900a1a1c686a56e16fa5417fa1 (patch) | |
tree | 6eaab18b57cd1386e117381346b0de929c9319e0 /src/net.cpp | |
parent | 6f01dcf63873a5e42798635ab4026c9a5f9fa213 (diff) |
net: split socket creation out of connection
Also, check for the correct error during socket creation
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp index 5eaeaab8f6..8f15842150 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -417,16 +417,30 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo if (addrConnect.IsValid()) { bool proxyConnectionFailed = false; - if (GetProxy(addrConnect.GetNetwork(), proxy)) + if (GetProxy(addrConnect.GetNetwork(), proxy)) { + hSocket = CreateSocket(proxy.proxy); + if (hSocket == INVALID_SOCKET) { + return nullptr; + } connected = ConnectThroughProxy(proxy, addrConnect.ToStringIP(), addrConnect.GetPort(), hSocket, nConnectTimeout, &proxyConnectionFailed); - else // no proxy needed (none set for target network) + } else { + // no proxy needed (none set for target network) + hSocket = CreateSocket(addrConnect); + if (hSocket == INVALID_SOCKET) { + return nullptr; + } connected = ConnectSocketDirectly(addrConnect, hSocket, nConnectTimeout); + } if (!proxyConnectionFailed) { // If a connection to the node was attempted, and failure (if any) is not caused by a problem connecting to // the proxy, mark this as an attempt. addrman.Attempt(addrConnect, fCountFailure); } } else if (pszDest && GetNameProxy(proxy)) { + hSocket = CreateSocket(proxy.proxy); + if (hSocket == INVALID_SOCKET) { + return nullptr; + } std::string host; int port = default_port; SplitHostPort(std::string(pszDest), port, host); |