summaryrefslogtreecommitdiff
path: root/lib/hostip6.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-01-26 17:51:01 +0100
committerDaniel Stenberg <daniel@haxx.se>2020-01-28 08:03:22 +0100
commit0b030a5b232bd9fc4fed90f0d1aaac69c189aa22 (patch)
tree0ca314f27beda02318a970993b0e3e9cd1ebcd8d /lib/hostip6.c
parent872ea75acfe3405f1d3b18a07d70696c3d63a100 (diff)
downloadcurl-0b030a5b232bd9fc4fed90f0d1aaac69c189aa22.tar.gz
global_init: move the IPv6 works status bool to multi handle
Previously it was stored in a global state which contributed to curl_global_init's thread unsafety. This boolean is now instead figured out in curl_multi_init() and stored in the multi handle. Less effective, but thread safe. Closes #4851
Diffstat (limited to 'lib/hostip6.c')
-rw-r--r--lib/hostip6.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/hostip6.c b/lib/hostip6.c
index e0e0c58df..41ff98696 100644
--- a/lib/hostip6.c
+++ b/lib/hostip6.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -62,13 +62,19 @@
/*
* Curl_ipv6works() returns TRUE if IPv6 seems to work.
*/
-bool Curl_ipv6works(void)
+bool Curl_ipv6works(struct connectdata *conn)
{
- /* the nature of most system is that IPv6 status doesn't come and go
- during a program's lifetime so we only probe the first time and then we
- have the info kept for fast re-use */
- static int ipv6_works = -1;
- if(-1 == ipv6_works) {
+ if(conn) {
+ /* the nature of most system is that IPv6 status doesn't come and go
+ during a program's lifetime so we only probe the first time and then we
+ have the info kept for fast re-use */
+ DEBUGASSERT(conn);
+ DEBUGASSERT(conn->data);
+ DEBUGASSERT(conn->data->multi);
+ return conn->data->multi->ipv6_works;
+ }
+ else {
+ int ipv6_works = -1;
/* probe to see if we have a working IPv6 stack */
curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
if(s == CURL_SOCKET_BAD)
@@ -78,8 +84,8 @@ bool Curl_ipv6works(void)
ipv6_works = 1;
Curl_closesocket(NULL, s);
}
+ return (ipv6_works>0)?TRUE:FALSE;
}
- return (ipv6_works>0)?TRUE:FALSE;
}
/*
@@ -89,7 +95,7 @@ bool Curl_ipv6works(void)
bool Curl_ipvalid(struct connectdata *conn)
{
if(conn->ip_version == CURL_IPRESOLVE_V6)
- return Curl_ipv6works();
+ return Curl_ipv6works(conn);
return TRUE;
}
@@ -159,7 +165,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
break;
}
- if((pf != PF_INET) && !Curl_ipv6works())
+ if((pf != PF_INET) && !Curl_ipv6works(conn))
/* The stack seems to be a non-IPv6 one */
pf = PF_INET;