1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 16:18:48 -05:00

Eliminate a unnecessary socket creation in Curl_getaddrinfo for an IPv4

address in an IPv6 capable libcurl.
This commit is contained in:
Dan Fandrich 2008-07-27 02:20:34 +00:00
parent 052f9ddedb
commit 432945e422

View File

@ -233,14 +233,29 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
char sbuf[NI_MAXSERV]; char sbuf[NI_MAXSERV];
char *sbufptr = NULL; char *sbufptr = NULL;
char addrbuf[128]; char addrbuf[128];
curl_socket_t s;
int pf; int pf;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
*waitp=0; /* don't wait, we have the response now */ *waitp=0; /* don't wait, we have the response now */
/*
* Check if a limited name resolve has been requested.
*/
switch(data->set.ip_version) {
case CURL_IPRESOLVE_V4:
pf = PF_INET;
break;
case CURL_IPRESOLVE_V6:
pf = PF_INET6;
break;
default:
pf = PF_UNSPEC;
break;
}
if (pf != PF_INET) {
/* see if we have an IPv6 stack */ /* see if we have an IPv6 stack */
s = socket(PF_INET6, SOCK_DGRAM, 0); curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
if(s == CURL_SOCKET_BAD) { if(s == CURL_SOCKET_BAD) {
/* Some non-IPv6 stacks have been found to make very slow name resolves /* Some non-IPv6 stacks have been found to make very slow name resolves
* when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
@ -253,20 +268,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
* possible checks. And close the socket again. * possible checks. And close the socket again.
*/ */
sclose(s); sclose(s);
/*
* Check if a more limited name resolve has been requested.
*/
switch(data->set.ip_version) {
case CURL_IPRESOLVE_V4:
pf = PF_INET;
break;
case CURL_IPRESOLVE_V6:
pf = PF_INET6;
break;
default:
pf = PF_UNSPEC;
break;
} }
} }