mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
Move SocketEvents logic to private method.
This separates the select() logic from the socket handling logic, setting up for a switch to poll().
This commit is contained in:
parent
ccc3f267ba
commit
7c022a20a1
36
src/net.cpp
36
src/net.cpp
@ -1390,7 +1390,7 @@ bool CConnman::GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &s
|
|||||||
return !recv_set.empty() || !send_set.empty() || !error_set.empty();
|
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;
|
std::set<SOCKET> recv_select_set, send_select_set, error_select_set;
|
||||||
if (!GenerateSelectSet(recv_select_set, send_select_set, error_select_set)) {
|
if (!GenerateSelectSet(recv_select_set, send_select_set, error_select_set)) {
|
||||||
@ -1470,12 +1470,38 @@ void CConnman::SocketHandler()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
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
|
// Accept new connections
|
||||||
//
|
//
|
||||||
for (const ListenSocket& hListenSocket : vhListenSocket)
|
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);
|
AcceptConnection(hListenSocket);
|
||||||
}
|
}
|
||||||
@ -1500,9 +1526,9 @@ void CConnman::SocketHandler()
|
|||||||
LOCK(pnode->cs_hSocket);
|
LOCK(pnode->cs_hSocket);
|
||||||
if (pnode->hSocket == INVALID_SOCKET)
|
if (pnode->hSocket == INVALID_SOCKET)
|
||||||
continue;
|
continue;
|
||||||
recvSet = FD_ISSET(pnode->hSocket, &fdsetRecv);
|
recvSet = recv_set.count(pnode->hSocket) > 0;
|
||||||
sendSet = FD_ISSET(pnode->hSocket, &fdsetSend);
|
sendSet = send_set.count(pnode->hSocket) > 0;
|
||||||
errorSet = FD_ISSET(pnode->hSocket, &fdsetError);
|
errorSet = error_set.count(pnode->hSocket) > 0;
|
||||||
}
|
}
|
||||||
if (recvSet || errorSet)
|
if (recvSet || errorSet)
|
||||||
{
|
{
|
||||||
|
@ -478,6 +478,7 @@ private:
|
|||||||
void NotifyNumConnectionsChanged();
|
void NotifyNumConnectionsChanged();
|
||||||
void InactivityCheck(CNode *pnode);
|
void InactivityCheck(CNode *pnode);
|
||||||
bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
|
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 SocketHandler();
|
||||||
void ThreadSocketHandler();
|
void ThreadSocketHandler();
|
||||||
void ThreadDNSAddressSeed();
|
void ThreadDNSAddressSeed();
|
||||||
|
Loading…
Reference in New Issue
Block a user