| 41 | } |
| 42 | |
| 43 | openhd::TCPServer::~TCPServer() { |
| 44 | // debug_if("TCPEndpoint::~TCPEndpoint() begin"); |
| 45 | // First we make sure we don't accept any new connections anymore |
| 46 | m_keep_accept_thread_alive = false; |
| 47 | shutdown(server_fd, SHUT_RDWR); // This will break out of select |
| 48 | m_accept_thread->join(); |
| 49 | m_accept_thread = nullptr; |
| 50 | server_fd = 0; |
| 51 | // Then we make sure to clean up any connected client(s) (If there are any) |
| 52 | for (const auto& client : m_clients_list) { |
| 53 | client->marked_to_be_removed = true; |
| 54 | client->keep_rx_looping = false; |
| 55 | shutdown(client->sock_fd, SHUT_RDWR); |
| 56 | client->rx_loop_thread->join(); |
| 57 | client->rx_loop_thread = nullptr; |
| 58 | } |
| 59 | m_console->debug("TCPEndpoint::~TCPEndpoint() end"); |
| 60 | } |
| 61 | |
| 62 | void openhd::TCPServer::loop_accept() { |
| 63 | struct sockaddr_in sockaddr {}; |