Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 1,260 Lines • ▼ Show 20 Lines | for (const ListenSocket &hListenSocket : vhListenSocket) { | ||||
recv_set.insert(pnode->hSocket); | recv_set.insert(pnode->hSocket); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
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, | if (!GenerateSelectSet(recv_select_set, send_select_set, | ||||
error_select_set)) { | error_select_set)) { | ||||
interruptNet.sleep_for( | interruptNet.sleep_for( | ||||
std::chrono::milliseconds(SELECT_TIMEOUT_MILLISECONDS)); | std::chrono::milliseconds(SELECT_TIMEOUT_MILLISECONDS)); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (nSelect == SOCKET_ERROR) { | ||||
FD_ZERO(&fdsetSend); | FD_ZERO(&fdsetSend); | ||||
FD_ZERO(&fdsetError); | FD_ZERO(&fdsetError); | ||||
if (!interruptNet.sleep_for( | if (!interruptNet.sleep_for( | ||||
std::chrono::milliseconds(SELECT_TIMEOUT_MILLISECONDS))) { | std::chrono::milliseconds(SELECT_TIMEOUT_MILLISECONDS))) { | ||||
return; | 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 | // Accept new connections | ||||
// | // | ||||
for (const ListenSocket &hListenSocket : vhListenSocket) { | for (const ListenSocket &hListenSocket : vhListenSocket) { | ||||
if (hListenSocket.socket != INVALID_SOCKET && | if (hListenSocket.socket != INVALID_SOCKET && | ||||
FD_ISSET(hListenSocket.socket, &fdsetRecv)) { | recv_set.count(hListenSocket.socket) > 0) { | ||||
AcceptConnection(hListenSocket); | AcceptConnection(hListenSocket); | ||||
} | } | ||||
} | } | ||||
// | // | ||||
// Service each socket | // Service each socket | ||||
// | // | ||||
std::vector<CNode *> vNodesCopy; | std::vector<CNode *> vNodesCopy; | ||||
Show All 15 Lines | for (CNode *pnode : vNodesCopy) { | ||||
bool recvSet = false; | bool recvSet = false; | ||||
bool sendSet = false; | bool sendSet = false; | ||||
bool errorSet = false; | bool errorSet = false; | ||||
{ | { | ||||
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) { | ||||
// typical socket buffer is 8K-64K | // typical socket buffer is 8K-64K | ||||
char pchBuf[0x10000]; | char pchBuf[0x10000]; | ||||
int32_t nBytes = 0; | int32_t nBytes = 0; | ||||
{ | { | ||||
LOCK(pnode->cs_hSocket); | LOCK(pnode->cs_hSocket); | ||||
if (pnode->hSocket == INVALID_SOCKET) { | if (pnode->hSocket == INVALID_SOCKET) { | ||||
▲ Show 20 Lines • Show All 1,568 Lines • Show Last 20 Lines |