@@ -1152,9 +1152,6 @@ void CConnman::ThreadSocketHandler()
11521152 {
11531153 if (pnode->hSocket == INVALID_SOCKET)
11541154 continue ;
1155- FD_SET (pnode->hSocket , &fdsetError);
1156- hSocketMax = std::max (hSocketMax, pnode->hSocket );
1157- have_fds = true ;
11581155
11591156 // Implement the following logic:
11601157 // * If there is data to send, select() for sending data. As this only
@@ -1166,16 +1163,24 @@ void CConnman::ThreadSocketHandler()
11661163 // receiving data.
11671164 // * Hand off all complete messages to the processor, to be handled without
11681165 // blocking here.
1166+
1167+ bool select_recv = !pnode->fPauseRecv ;
1168+ bool select_send;
11691169 {
11701170 LOCK (pnode->cs_vSend );
1171- if (!pnode->vSendMsg .empty ()) {
1172- FD_SET (pnode->hSocket , &fdsetSend);
1173- continue ;
1174- }
1171+ select_send = !pnode->vSendMsg .empty ();
11751172 }
1176- {
1177- if (!pnode->fPauseRecv )
1178- FD_SET (pnode->hSocket , &fdsetRecv);
1173+
1174+ FD_SET (pnode->hSocket , &fdsetError);
1175+ hSocketMax = std::max (hSocketMax, pnode->hSocket );
1176+ have_fds = true ;
1177+
1178+ if (select_send) {
1179+ FD_SET (pnode->hSocket , &fdsetSend);
1180+ continue ;
1181+ }
1182+ if (select_recv) {
1183+ FD_SET (pnode->hSocket , &fdsetRecv);
11791184 }
11801185 }
11811186 }
@@ -1229,9 +1234,15 @@ void CConnman::ThreadSocketHandler()
12291234 //
12301235 // Receive
12311236 //
1237+ bool recvSet = false ;
1238+ bool sendSet = false ;
1239+ bool errorSet = false ;
12321240 if (pnode->hSocket == INVALID_SOCKET)
12331241 continue ;
1234- if (FD_ISSET (pnode->hSocket , &fdsetRecv) || FD_ISSET (pnode->hSocket , &fdsetError))
1242+ recvSet = FD_ISSET (pnode->hSocket , &fdsetRecv);
1243+ sendSet = FD_ISSET (pnode->hSocket , &fdsetSend);
1244+ errorSet = FD_ISSET (pnode->hSocket , &fdsetError);
1245+ if (recvSet || errorSet)
12351246 {
12361247 {
12371248 {
@@ -1286,9 +1297,7 @@ void CConnman::ThreadSocketHandler()
12861297 //
12871298 // Send
12881299 //
1289- if (pnode->hSocket == INVALID_SOCKET)
1290- continue ;
1291- if (FD_ISSET (pnode->hSocket , &fdsetSend))
1300+ if (sendSet)
12921301 {
12931302 LOCK (pnode->cs_vSend );
12941303 size_t nBytes = SocketSendData (pnode);
0 commit comments