public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-3262] libstdc++: Improve error handling in Net TS name resolution Date: Tue, 31 Aug 2021 16:37:24 +0000 (GMT) [thread overview] Message-ID: <20210831163724.674AE3857C69@sourceware.org> (raw) https://gcc.gnu.org/g:feec7ef6672bf28d5c79950a21d435533a10710d commit r12-3262-gfeec7ef6672bf28d5c79950a21d435533a10710d Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Aug 31 13:09:26 2021 +0100 libstdc++: Improve error handling in Net TS name resolution Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/experimental/internet (__make_resolver_error_code): Handle EAI_SYSTEM errors. (basic_resolver_results): Use __make_resolver_error_code. Use Glibc NI_MAXHOST and NI_MAXSERV values for buffer sizes. Diff: --- libstdc++-v3/include/experimental/internet | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet index 6ce070ae775..65c97de07d9 100644 --- a/libstdc++-v3/include/experimental/internet +++ b/libstdc++-v3/include/experimental/internet @@ -89,6 +89,12 @@ namespace ip host_not_found = EAI_NONAME, host_not_found_try_again = EAI_AGAIN, service_not_found = EAI_SERVICE + // N.B. POSIX defines additional errors that have no enumerator here: + // EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_SOCKTYPE, EAI_SYSTEM + // Some C libraries define additional errors: + // EAI_BADHINTS, EAI_OVERFLOW, EAI_PROTOCOL + // Some C libraries define additional (obsolete?) errors: + // EAI_ADDRFAMILY, EAI_NODATA #endif }; @@ -117,6 +123,19 @@ namespace ip inline error_condition make_error_condition(resolver_errc __e) noexcept { return error_condition(static_cast<int>(__e), resolver_category()); } + /// @cond undocumented + inline error_code + __make_resolver_error_code(int __ai_err, + [[__maybe_unused__]] int __sys_err) noexcept + { +#ifdef EAI_SYSTEM + if (__builtin_expect(__ai_err == EAI_SYSTEM, 0)) + return error_code(__sys_err, std::generic_category()); +#endif + return error_code(__ai_err, resolver_category()); + } + /// @endcond + /// @} using port_type = uint_least16_t; ///< Type used for port numbers. @@ -2011,7 +2030,7 @@ namespace ip if (int __err = ::getaddrinfo(__h, __s, &__hints, &__sai._M_p)) { - __ec.assign(__err, resolver_category()); + __ec = ip::__make_resolver_error_code(__err, errno); return; } __ec.clear(); @@ -2040,8 +2059,8 @@ namespace ip basic_resolver_results(const endpoint_type& __ep, error_code& __ec) { #ifdef _GLIBCXX_HAVE_NETDB_H - char __host_name[256]; - char __service_name[128]; + char __host_name[1025]; // glibc NI_MAXHOST + char __service_name[32]; // glibc NI_MAXSERV int __flags = 0; if (__ep.protocol().type() == SOCK_DGRAM) __flags |= NI_DGRAM; @@ -2059,7 +2078,7 @@ namespace ip __flags); } if (__err) - __ec.assign(__err, resolver_category()); + __ec = ip::__make_resolver_error_code(__err, errno); else { __ec.clear();
reply other threads:[~2021-08-31 16:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210831163724.674AE3857C69@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).