Home » Community » U++ community news and announcements » TcpSocket::Connect now prefers IPv4 over IPv6
TcpSocket::Connect now prefers IPv4 over IPv6 [message #37596] |
Tue, 23 October 2012 15:18  |
 |
mirek
Messages: 14261 Registered: November 2005
|
Ultimate Member |
|
|
After encountering the first site with IPv6 support, which did not go that well (I suspect network issues), I have for now changes Tcp::Connect to prefer IPv4 connection when available
bool TcpSocket::RawConnect(addrinfo *arp)
{
if(!arp) {
SetSockError("connect", -1, "not found");
return false;
}
for(int pass = 0; pass < 2; pass++) {
addrinfo *rp = arp;
while(rp) {
if(rp->ai_family == AF_INET == !pass && // Try to connect IPv4 in the first pass
Open(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) {
if(connect(socket, rp->ai_addr, (int)rp->ai_addrlen) == 0 ||
GetErrorCode() == SOCKERR(EINPROGRESS) || GetErrorCode() == SOCKERR(EWOULDBLOCK)
) {
mode = CONNECT;
return true;
}
Close();
}
rp = rp->ai_next;
}
}
SetSockError("connect", -1, "failed");
return false;
}
|
|
|
|
|
Goto Forum:
Current Time: Tue Jun 17 04:36:53 CEST 2025
Total time taken to generate the page: 0.04054 seconds
|