| 154 | } |
| 155 | |
| 156 | host_t host_create(af_e af, ENetAddress &addr, std::uint16_t port) { |
| 157 | static std::once_flag enet_init_flag; |
| 158 | std::call_once(enet_init_flag, []() { |
| 159 | enet_initialize(); |
| 160 | }); |
| 161 | |
| 162 | auto any_addr = net::af_to_any_address_string(af); |
| 163 | enet_address_set_host(&addr, any_addr.data()); |
| 164 | enet_address_set_port(&addr, port); |
| 165 | |
| 166 | // Maximum of 128 clients, which should be enough for anyone |
| 167 | auto host = host_t {enet_host_create(af == IPV4 ? AF_INET : AF_INET6, &addr, 128, 0, 0, 0)}; |
| 168 | |
| 169 | // Enable opportunistic QoS tagging (automatically disables if the network appears to drop tagged packets) |
| 170 | enet_socket_set_option(host->socket, ENET_SOCKOPT_QOS, 1); |
| 171 | |
| 172 | return host; |
| 173 | } |
| 174 | |
| 175 | void free_host(ENetHost *host) { |
| 176 | std::for_each(host->peers, host->peers + host->peerCount, [](ENetPeer &peer_ref) { |
no test coverage detected