public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Improve error handling in Net TS name resolution
@ 2021-08-31 16:38 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-08-31 16:38 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 337 bytes --]

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.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2801 bytes --]

commit feec7ef6672bf28d5c79950a21d435533a10710d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Aug 31 13:09:26 2021

    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 --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();

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-31 16:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 16:38 [committed] libstdc++: Improve error handling in Net TS name resolution Jonathan Wakely

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).