@@ -1152,9 +1152,6 @@ void CConnman::ThreadSocketHandler()
1152
1152
{
1153
1153
if (pnode->hSocket == INVALID_SOCKET)
1154
1154
continue ;
1155
- FD_SET (pnode->hSocket , &fdsetError);
1156
- hSocketMax = std::max (hSocketMax, pnode->hSocket );
1157
- have_fds = true ;
1158
1155
1159
1156
// Implement the following logic:
1160
1157
// * If there is data to send, select() for sending data. As this only
@@ -1166,16 +1163,24 @@ void CConnman::ThreadSocketHandler()
1166
1163
// receiving data.
1167
1164
// * Hand off all complete messages to the processor, to be handled without
1168
1165
// blocking here.
1166
+
1167
+ bool select_recv = !pnode->fPauseRecv ;
1168
+ bool select_send;
1169
1169
{
1170
1170
LOCK (pnode->cs_vSend );
1171
- if (!pnode->vSendMsg .empty ()) {
1172
- FD_SET (pnode->hSocket , &fdsetSend);
1173
- continue ;
1174
- }
1171
+ select_send = !pnode->vSendMsg .empty ();
1175
1172
}
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);
1179
1184
}
1180
1185
}
1181
1186
}
@@ -1229,9 +1234,15 @@ void CConnman::ThreadSocketHandler()
1229
1234
//
1230
1235
// Receive
1231
1236
//
1237
+ bool recvSet = false ;
1238
+ bool sendSet = false ;
1239
+ bool errorSet = false ;
1232
1240
if (pnode->hSocket == INVALID_SOCKET)
1233
1241
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)
1235
1246
{
1236
1247
{
1237
1248
{
@@ -1286,9 +1297,7 @@ void CConnman::ThreadSocketHandler()
1286
1297
//
1287
1298
// Send
1288
1299
//
1289
- if (pnode->hSocket == INVALID_SOCKET)
1290
- continue ;
1291
- if (FD_ISSET (pnode->hSocket , &fdsetSend))
1300
+ if (sendSet)
1292
1301
{
1293
1302
LOCK (pnode->cs_vSend );
1294
1303
size_t nBytes = SocketSendData (pnode);
0 commit comments