cpp-httplib: Enable IPV6_V6ONLY flag to increase reliability of IPv4 service, as there are separate sockets for IPv4 and IPv6

This commit is contained in:
Alexander Sagen 2024-08-14 12:59:43 +02:00
parent f176e2539e
commit 25ae2ff0b8
No known key found for this signature in database
GPG key ID: C1B6BD677756F470

View file

@ -3163,13 +3163,13 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
if (socket_options) { socket_options(sock); }
if (rp->ai_family == AF_INET6) {
auto no = 0;
auto yes = 1;
#ifdef _WIN32
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
reinterpret_cast<const char *>(&no), sizeof(no));
reinterpret_cast<const char *>(&yes), sizeof(yes));
#else
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
reinterpret_cast<const void *>(&no), sizeof(no));
reinterpret_cast<const void *>(&yes), sizeof(yes));
#endif
}