diff options
author | Patrick Strateman <patrick.strateman@gmail.com> | 2015-08-13 02:16:46 -0700 |
---|---|---|
committer | Patrick Strateman <patrick.strateman@gmail.com> | 2015-08-22 15:38:23 -0700 |
commit | 1ef481761477e26651dc56b4378b146cd5c416db (patch) | |
tree | db1df3a748cbb90d3c06efc7bfc3f2496f2688fa /src/net.cpp | |
parent | 541a1dd9e664ac0b3929abeac42190ac8e88fc21 (diff) |
Refactor: Bail early in AcceptConnection
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/net.cpp b/src/net.cpp index 8f1db2695e..6214c754c3 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -801,39 +801,46 @@ static void AcceptConnection(const ListenSocket& hListenSocket) { int nErr = WSAGetLastError(); if (nErr != WSAEWOULDBLOCK) LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr)); + return; } - else if (!IsSelectableSocket(hSocket)) + + if (!IsSelectableSocket(hSocket)) { LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString()); CloseSocket(hSocket); + return; } - else if (nInbound >= nMaxInbound) + + if (nInbound >= nMaxInbound) { LogPrint("net", "connection from %s dropped (full)\n", addr.ToString()); CloseSocket(hSocket); + return; } - else if (!whitelisted && (nInbound >= (nMaxInbound - nWhiteConnections))) + + if (!whitelisted && (nInbound >= (nMaxInbound - nWhiteConnections))) { LogPrint("net", "connection from %s dropped (non-whitelisted)\n", addr.ToString()); CloseSocket(hSocket); + return; } - else if (CNode::IsBanned(addr) && !whitelisted) + + if (CNode::IsBanned(addr) && !whitelisted) { LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); CloseSocket(hSocket); + return; } - else - { - CNode* pnode = new CNode(hSocket, addr, "", true); - pnode->AddRef(); - pnode->fWhitelisted = whitelisted; - LogPrint("net", "connection from %s accepted\n", addr.ToString()); + CNode* pnode = new CNode(hSocket, addr, "", true); + pnode->AddRef(); + pnode->fWhitelisted = whitelisted; - { - LOCK(cs_vNodes); - vNodes.push_back(pnode); - } + LogPrint("net", "connection from %s accepted\n", addr.ToString()); + + { + LOCK(cs_vNodes); + vNodes.push_back(pnode); } } |