| 1171 | } |
| 1172 | |
| 1173 | void ThreadMessageHandler() { |
| 1174 | SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); |
| 1175 | while (true) { |
| 1176 | bool fHaveSyncNode = false; |
| 1177 | |
| 1178 | vector<CNode*> vNodesCopy; |
| 1179 | { |
| 1180 | LOCK(cs_vNodes); |
| 1181 | vNodesCopy = vNodes; |
| 1182 | for (auto pNode : vNodesCopy) { |
| 1183 | pNode->AddRef(); |
| 1184 | if (pNode == pnodeSync) |
| 1185 | fHaveSyncNode = true; |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | if (!fHaveSyncNode) |
| 1190 | StartSync(vNodesCopy); |
| 1191 | |
| 1192 | // Poll the connected nodes for messages |
| 1193 | CNode* pnodeTrickle = nullptr; |
| 1194 | if (!vNodesCopy.empty()) |
| 1195 | pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())]; |
| 1196 | |
| 1197 | bool fSleep = true; |
| 1198 | |
| 1199 | for (auto pNode : vNodesCopy) { |
| 1200 | if (pNode->fDisconnect) |
| 1201 | continue; |
| 1202 | |
| 1203 | // Receive messages |
| 1204 | { |
| 1205 | TRY_LOCK(pNode->cs_vRecvMsg, lockRecv); |
| 1206 | if (lockRecv) { |
| 1207 | if (!GetNodeSignals().ProcessMessages(pNode)) |
| 1208 | pNode->CloseSocketDisconnect(); |
| 1209 | |
| 1210 | if (pNode->nSendSize < SendBufferSize()) { |
| 1211 | if (!pNode->vRecvGetData.empty() || |
| 1212 | (!pNode->vRecvMsg.empty() && pNode->vRecvMsg[0].complete())) { |
| 1213 | fSleep = false; |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | boost::this_thread::interruption_point(); |
| 1219 | |
| 1220 | // Send messages |
| 1221 | { |
| 1222 | TRY_LOCK(pNode->cs_vSend, lockSend); |
| 1223 | if (lockSend) |
| 1224 | GetNodeSignals().SendMessages(pNode, pNode == pnodeTrickle); |
| 1225 | } |
| 1226 | |
| 1227 | boost::this_thread::interruption_point(); |
| 1228 | } |
| 1229 | |
| 1230 | { |
nothing calls this directly
no test coverage detected