Commit f0b31080 authored by Paul Eggert's avatar Paul Eggert

Minor fixes for getaddrinfo_a usage

* src/process.c (Fdelete_process): Check gai_cancel return value.
That way, there’s no need to invoke gai_error.  Check gai_suspend
return value.
(Fmake_network_process): Don’t assume gai_strerror returns a UTF-8
string.  Simplify call to connect_network_socket.
(check_for_dns): Avoid unnecessary initialization of local.
parent 7801999f
...@@ -845,23 +845,19 @@ nil, indicating the current buffer's process. */) ...@@ -845,23 +845,19 @@ nil, indicating the current buffer's process. */)
#ifdef HAVE_GETADDRINFO_A #ifdef HAVE_GETADDRINFO_A
if (p->dns_request) if (p->dns_request)
{ {
int ret; /* Cancel the request. Unless shutting down, wait until
completion. Free the request if completely canceled. */
gai_cancel (p->dns_request); bool canceled = gai_cancel (p->dns_request) != EAI_NOTCANCELED;
ret = gai_error (p->dns_request); if (!canceled && !inhibit_sentinels)
if (ret == EAI_CANCELED || ret == 0)
free_dns_request (process);
else
{ {
/* If we're called during shutdown, we don't really about struct gaicb const *req = p->dns_request;
freeing all the resources. Otherwise wait until while (gai_suspend (&req, 1, NULL) != 0)
completion, and then free the request. */ continue;
if (! inhibit_sentinels) canceled = true;
{
gai_suspend ((struct gaicb const **) &p->dns_request, 1, NULL);
free_dns_request (process);
}
} }
if (canceled)
free_dns_request (process);
} }
#endif #endif
...@@ -3814,7 +3810,14 @@ usage: (make-network-process &rest ARGS) */) ...@@ -3814,7 +3810,14 @@ usage: (make-network-process &rest ARGS) */)
ret = getaddrinfo (SSDATA (host), portstring, &hints, &res); ret = getaddrinfo (SSDATA (host), portstring, &hints, &res);
if (ret) if (ret)
#ifdef HAVE_GAI_STRERROR #ifdef HAVE_GAI_STRERROR
error ("%s/%s %s", SSDATA (host), portstring, gai_strerror (ret)); {
synchronize_system_messages_locale ();
char const *str = gai_strerror (ret);
if (! NILP (Vlocale_coding_system))
str = SSDATA (code_convert_string_norecord
(build_string (str), Vlocale_coding_system, 0));
error ("%s/%s %s", SSDATA (host), portstring, str);
}
#else #else
error ("%s/%s getaddrinfo error %d", SSDATA (host), portstring, ret); error ("%s/%s getaddrinfo error %d", SSDATA (host), portstring, ret);
#endif #endif
...@@ -3932,21 +3935,17 @@ usage: (make-network-process &rest ARGS) */) ...@@ -3932,21 +3935,17 @@ usage: (make-network-process &rest ARGS) */)
} }
#ifdef HAVE_GETADDRINFO_A #ifdef HAVE_GETADDRINFO_A
/* If we're doing async address resolution, the list of addresses /* With async address resolution, the list of addresses is empty, so
here will be nil, so we postpone connecting to the server. */ postpone connecting to the server. */
if (!p->is_server && NILP (ip_addresses)) if (!p->is_server && NILP (ip_addresses))
{ {
p->dns_request = dns_request; p->dns_request = dns_request;
p->status = Qconnect; p->status = Qconnect;
return proc;
} }
else
{
connect_network_socket (proc, ip_addresses);
}
#else /* HAVE_GETADDRINFO_A */
connect_network_socket (proc, ip_addresses);
#endif #endif
connect_network_socket (proc, ip_addresses);
return proc; return proc;
} }
...@@ -4657,13 +4656,12 @@ check_for_dns (Lisp_Object proc) ...@@ -4657,13 +4656,12 @@ check_for_dns (Lisp_Object proc)
{ {
struct Lisp_Process *p = XPROCESS (proc); struct Lisp_Process *p = XPROCESS (proc);
Lisp_Object ip_addresses = Qnil; Lisp_Object ip_addresses = Qnil;
int ret = 0;
/* Sanity check. */ /* Sanity check. */
if (! p->dns_request) if (! p->dns_request)
return Qnil; return Qnil;
ret = gai_error (p->dns_request); int ret = gai_error (p->dns_request);
if (ret == EAI_INPROGRESS) if (ret == EAI_INPROGRESS)
return Qt; return Qt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment