diff options
author | Patrick Strateman <patrick.strateman@gmail.com> | 2018-09-26 21:51:46 -0400 |
---|---|---|
committer | Patrick Strateman <patrick.strateman@gmail.com> | 2018-11-30 18:02:51 -0500 |
commit | 28211a4bc9c65859b641b81a0541726a0e01988f (patch) | |
tree | 18d635f6bf4b467c253520bf14952ae2a2bf029b /src | |
parent | 7e403c0ae705455aa66f7df9a9a99f462fd4e9a8 (diff) |
Move SocketEvents logic to private method.
This separates the select() logic from the socket handling logic, setting up
for a switch to poll().
Diffstat (limited to 'src')
-rw-r--r-- | src/net.cpp | 36 | ||||
-rw-r--r-- | src/net.h | 1 |
2 files changed, 32 insertions, 5 deletions
diff --git a/src/net.cpp b/src/net.cpp index 9d837192af..2664828034 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1307,7 +1307,7 @@ bool CConnman::GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &s return !recv_set.empty() || !send_set.empty() || !error_set.empty(); } -void CConnman::SocketHandler() +void CConnman::SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set) { std::set<SOCKET> recv_select_set, send_select_set, error_select_set; if (!GenerateSelectSet(recv_select_set, send_select_set, error_select_set)) { @@ -1362,12 +1362,38 @@ void CConnman::SocketHandler() return; } + for (SOCKET hSocket : recv_select_set) { + if (FD_ISSET(hSocket, &fdsetRecv)) { + recv_set.insert(hSocket); + } + } + + for (SOCKET hSocket : send_select_set) { + if (FD_ISSET(hSocket, &fdsetSend)) { + send_set.insert(hSocket); + } + } + + for (SOCKET hSocket : error_select_set) { + if (FD_ISSET(hSocket, &fdsetError)) { + error_set.insert(hSocket); + } + } +} + +void CConnman::SocketHandler() +{ + std::set<SOCKET> recv_set, send_set, error_set; + SocketEvents(recv_set, send_set, error_set); + + if (interruptNet) return; + // // Accept new connections // for (const ListenSocket& hListenSocket : vhListenSocket) { - if (hListenSocket.socket != INVALID_SOCKET && FD_ISSET(hListenSocket.socket, &fdsetRecv)) + if (hListenSocket.socket != INVALID_SOCKET && recv_set.count(hListenSocket.socket) > 0) { AcceptConnection(hListenSocket); } @@ -1398,9 +1424,9 @@ void CConnman::SocketHandler() LOCK(pnode->cs_hSocket); if (pnode->hSocket == INVALID_SOCKET) continue; - recvSet = FD_ISSET(pnode->hSocket, &fdsetRecv); - sendSet = FD_ISSET(pnode->hSocket, &fdsetSend); - errorSet = FD_ISSET(pnode->hSocket, &fdsetError); + recvSet = recv_set.count(pnode->hSocket) > 0; + sendSet = send_set.count(pnode->hSocket) > 0; + errorSet = error_set.count(pnode->hSocket) > 0; } if (recvSet || errorSet) { @@ -343,6 +343,7 @@ private: void NotifyNumConnectionsChanged(); void InactivityCheck(CNode *pnode); bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set); + void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set); void SocketHandler(); void ThreadSocketHandler(); void ThreadDNSAddressSeed(); |