@@ -1295,7 +1295,7 @@ bool CConnman::GenerateSelectSet(std::set<SOCKET>& recv_set, std::set<SOCKET>& s
12951295 }
12961296 }
12971297
1298- #ifndef WIN32
1298+ #ifdef USE_WAKEUP_PIPE
12991299 // We add a pipe to the read set so that the select() call can be woken up from the outside
13001300 // This is done when data is added to send buffers (vSendMsg) or when new peers are added
13011301 // This is currently only implemented for POSIX compliant systems. This means that Windows will fall back to
@@ -1339,9 +1339,12 @@ void CConnman::SocketEvents(std::set<SOCKET>& recv_set, std::set<SOCKET>& send_s
13391339 vpollfds.push_back (std::move (it.second ));
13401340 }
13411341
1342- isInSelect = true ;
1343- if (poll (vpollfds.data (), vpollfds.size (), SELECT_TIMEOUT_MILLISECONDS) < 0 ) return ;
1344- isInSelect = false ;
1342+ wakeupSelectNeeded = true ;
1343+ int r = poll (vpollfds.data (), vpollfds.size (), SELECT_TIMEOUT_MILLISECONDS);
1344+ wakeupSelectNeeded = false ;
1345+ if (r < 0 ) {
1346+ return ;
1347+ }
13451348
13461349 if (interruptNet) return ;
13471350
@@ -1390,9 +1393,9 @@ void CConnman::SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_s
13901393 hSocketMax = std::max (hSocketMax, hSocket);
13911394 }
13921395
1393- isInSelect = true ;
1396+ wakeupSelectNeeded = true ;
13941397 int nSelect = select (hSocketMax + 1 , &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
1395- isInSelect = false ;
1398+ wakeupSelectNeeded = false ;
13961399
13971400 if (interruptNet)
13981401 return ;
@@ -1433,7 +1436,7 @@ void CConnman::SocketHandler()
14331436 std::set<SOCKET> recv_set, send_set, error_set;
14341437 SocketEvents (recv_set, send_set, error_set);
14351438
1436- #ifndef WIN32
1439+ #ifdef USE_WAKEUP_PIPE
14371440 // drain the wakeup pipe
14381441 if (recv_set.count (wakeupPipe[0 ])) {
14391442 LogPrint (BCLog::NET, " woke up select()\n " );
@@ -1563,7 +1566,7 @@ void CConnman::WakeMessageHandler()
15631566
15641567void CConnman::WakeSelect ()
15651568{
1566- #ifndef WIN32
1569+ #ifdef USE_WAKEUP_PIPE
15671570 if (wakeupPipe[1 ] == -1 ) {
15681571 return ;
15691572 }
@@ -1575,6 +1578,8 @@ void CConnman::WakeSelect()
15751578 LogPrint (BCLog::NET, " write to wakeupPipe failed\n " );
15761579 }
15771580#endif
1581+
1582+ wakeupSelectNeeded = false ;
15781583}
15791584
15801585static std::string GetDNSHost (const CDNSSeedData& data, ServiceFlags* requiredServiceBits)
@@ -2284,7 +2289,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
22842289 fMsgProcWake = false ;
22852290 }
22862291
2287- #ifndef WIN32
2292+ #ifdef USE_WAKEUP_PIPE
22882293 if (pipe (wakeupPipe) != 0 ) {
22892294 wakeupPipe[0 ] = wakeupPipe[1 ] = -1 ;
22902295 LogPrint (BCLog::NET, " pipe() for wakeupPipe failed\n " );
@@ -2429,7 +2434,7 @@ void CConnman::Stop()
24292434 vhListenSocket.clear ();
24302435 semOutbound.reset ();
24312436 semAddnode.reset ();
2432- #ifndef WIN32
2437+ #ifdef USE_WAKEUP_PIPE
24332438 if (wakeupPipe[0 ] != -1 ) close (wakeupPipe[0 ]);
24342439 if (wakeupPipe[1 ] != -1 ) close (wakeupPipe[1 ]);
24352440 wakeupPipe[0 ] = wakeupPipe[1 ] = -1 ;
@@ -2780,7 +2785,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg, bool allowOpti
27802785 if (optimisticSend == true )
27812786 nBytesSent = SocketSendData (pnode);
27822787 // wake up select() call in case there was no pending data before (so it was not selecting this socket for sending)
2783- else if (!hasPendingData && isInSelect )
2788+ else if (!hasPendingData && wakeupSelectNeeded )
27842789 WakeSelect ();
27852790 }
27862791 if (nBytesSent)
0 commit comments