| 2567 | #endif |
| 2568 | |
| 2569 | inline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) { |
| 2570 | using namespace std::chrono; |
| 2571 | auto start = steady_clock::now(); |
| 2572 | while (true) { |
| 2573 | auto val = select_read(sock, 0, 10000); |
| 2574 | if (val < 0) { |
| 2575 | return false; |
| 2576 | } else if (val == 0) { |
| 2577 | auto current = steady_clock::now(); |
| 2578 | auto duration = duration_cast<milliseconds>(current - start); |
| 2579 | auto timeout = keep_alive_timeout_sec * 1000; |
| 2580 | if (duration.count() > timeout) { return false; } |
| 2581 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); |
| 2582 | } else { |
| 2583 | return true; |
| 2584 | } |
| 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | template <typename T> |
| 2589 | inline bool |
no test coverage detected