diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2017-02-06 13:47:24 -0500 |
---|---|---|
committer | Cory Fields <cory-nospam-@coryfields.com> | 2017-02-06 14:48:50 -0500 |
commit | 45e2e085612463dd9cca9f1b221733afa6d52991 (patch) | |
tree | 61a599d965a34037f358eb5c03489d82206da0d0 | |
parent | 02464da5e4aa8c19d4fff3859dcdee822e2af78c (diff) | |
download | bitcoin-45e2e085612463dd9cca9f1b221733afa6d52991.tar.xz |
net: rearrange so that socket accesses can be grouped together
-rw-r--r-- | src/net.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/net.cpp b/src/net.cpp index 4d0d781d6d..b47514fd92 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1152,9 +1152,6 @@ void CConnman::ThreadSocketHandler() { if (pnode->hSocket == INVALID_SOCKET) continue; - FD_SET(pnode->hSocket, &fdsetError); - hSocketMax = std::max(hSocketMax, pnode->hSocket); - have_fds = true; // Implement the following logic: // * If there is data to send, select() for sending data. As this only @@ -1166,16 +1163,24 @@ void CConnman::ThreadSocketHandler() // receiving data. // * Hand off all complete messages to the processor, to be handled without // blocking here. + + bool select_recv = !pnode->fPauseRecv; + bool select_send; { LOCK(pnode->cs_vSend); - if (!pnode->vSendMsg.empty()) { - FD_SET(pnode->hSocket, &fdsetSend); - continue; - } + select_send = !pnode->vSendMsg.empty(); } - { - if (!pnode->fPauseRecv) - FD_SET(pnode->hSocket, &fdsetRecv); + + FD_SET(pnode->hSocket, &fdsetError); + hSocketMax = std::max(hSocketMax, pnode->hSocket); + have_fds = true; + + if (select_send) { + FD_SET(pnode->hSocket, &fdsetSend); + continue; + } + if (select_recv) { + FD_SET(pnode->hSocket, &fdsetRecv); } } } @@ -1229,9 +1234,15 @@ void CConnman::ThreadSocketHandler() // // Receive // + bool recvSet = false; + bool sendSet = false; + bool errorSet = false; if (pnode->hSocket == INVALID_SOCKET) continue; - if (FD_ISSET(pnode->hSocket, &fdsetRecv) || FD_ISSET(pnode->hSocket, &fdsetError)) + recvSet = FD_ISSET(pnode->hSocket, &fdsetRecv); + sendSet = FD_ISSET(pnode->hSocket, &fdsetSend); + errorSet = FD_ISSET(pnode->hSocket, &fdsetError); + if (recvSet || errorSet) { { { @@ -1286,9 +1297,7 @@ void CConnman::ThreadSocketHandler() // // Send // - if (pnode->hSocket == INVALID_SOCKET) - continue; - if (FD_ISSET(pnode->hSocket, &fdsetSend)) + if (sendSet) { LOCK(pnode->cs_vSend); size_t nBytes = SocketSendData(pnode); |