| 1464 | |
| 1465 | #ifdef USE_POLL |
| 1466 | void CConnman::SocketEvents(const std::vector<CNode*>& nodes, |
| 1467 | std::set<SOCKET>& recv_set, |
| 1468 | std::set<SOCKET>& send_set, |
| 1469 | std::set<SOCKET>& error_set) |
| 1470 | { |
| 1471 | std::set<SOCKET> recv_select_set, send_select_set, error_select_set; |
| 1472 | if (!GenerateSelectSet(nodes, recv_select_set, send_select_set, error_select_set)) { |
| 1473 | interruptNet.sleep_for(std::chrono::milliseconds(SELECT_TIMEOUT_MILLISECONDS)); |
| 1474 | return; |
| 1475 | } |
| 1476 | |
| 1477 | std::unordered_map<SOCKET, struct pollfd> pollfds; |
| 1478 | for (SOCKET socket_id : recv_select_set) { |
| 1479 | pollfds[socket_id].fd = socket_id; |
| 1480 | pollfds[socket_id].events |= POLLIN; |
| 1481 | } |
| 1482 | |
| 1483 | for (SOCKET socket_id : send_select_set) { |
| 1484 | pollfds[socket_id].fd = socket_id; |
| 1485 | pollfds[socket_id].events |= POLLOUT; |
| 1486 | } |
| 1487 | |
| 1488 | for (SOCKET socket_id : error_select_set) { |
| 1489 | pollfds[socket_id].fd = socket_id; |
| 1490 | // These flags are ignored, but we set them for clarity |
| 1491 | pollfds[socket_id].events |= POLLERR|POLLHUP; |
| 1492 | } |
| 1493 | |
| 1494 | std::vector<struct pollfd> vpollfds; |
| 1495 | vpollfds.reserve(pollfds.size()); |
| 1496 | for (auto it : pollfds) { |
| 1497 | vpollfds.push_back(std::move(it.second)); |
| 1498 | } |
| 1499 | |
| 1500 | if (poll(vpollfds.data(), vpollfds.size(), SELECT_TIMEOUT_MILLISECONDS) < 0) return; |
| 1501 | |
| 1502 | if (interruptNet) return; |
| 1503 | |
| 1504 | for (struct pollfd pollfd_entry : vpollfds) { |
| 1505 | if (pollfd_entry.revents & POLLIN) recv_set.insert(pollfd_entry.fd); |
| 1506 | if (pollfd_entry.revents & POLLOUT) send_set.insert(pollfd_entry.fd); |
| 1507 | if (pollfd_entry.revents & (POLLERR|POLLHUP)) error_set.insert(pollfd_entry.fd); |
| 1508 | } |
| 1509 | } |
| 1510 | #else |
| 1511 | void CConnman::SocketEvents(const std::vector<CNode*>& nodes, |
| 1512 | std::set<SOCKET>& recv_set, |