From f09a8e2be4db8bd22d65ed0ff25e59ed147be39e Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 13 Jun 2024 19:54:45 +0100 Subject: [PATCH] gioerror: Map EADDRNOTAVAIL to G_IO_ERROR_CONNECTION_REFUSED MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously it was mapped (as a default) to `G_IO_ERROR_FAILED`. It’s the error that macOS returns when trying to connect to a socket which is bound but not listened to. Linux returns `ECONNREFUSED` in this case. It’s helpful if they both map to the same `GIOError` value. This should fix the `/socket-client/connection-fail` test on macOS, which is currently [failing](https://gitlab.gnome.org/GNOME/glib/-/jobs/3970547) with: ``` # GLib-GIO-DEBUG: GSocketClient: Starting TCP connection attempt # GLib-GIO-DEBUG: GSocketClient: Connection attempt failed: Can't assign requested address # GLib-GIO-DEBUG: GSocketClient: Starting new address enumeration # GLib-GIO-DEBUG: GSocketClient: Address enumeration completed (out of addresses) # GLib-GIO-DEBUG: GSocketClient: Address enumeration failed: (null) # GLib-GIO-DEBUG: GSocketClient: Connection failed: Could not connect to localhost: Can't assign requested address not ok /socket-client/connection-fail - GLib-GIO:ERROR:../gio/tests/gsocketclient-slow.c:231:test_connection_failed: assertion failed (local_error == (g-io-error-quark, 39)): Could not connect to localhost: Can't assign requested address (g-io-error-quark, 0) Bail out! ``` Signed-off-by: Philip Withnall See: #3184 Fixes: #3394 --- gio/gioerror.c | 6 ++++++ gio/tests/error.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gio/gioerror.c b/gio/gioerror.c index 1b64dfd0b..8456afe4a 100644 --- a/gio/gioerror.c +++ b/gio/gioerror.c @@ -208,6 +208,12 @@ g_io_error_from_errno (gint err_no) break; #endif +#ifdef EADDRNOTAVAIL + case EADDRNOTAVAIL: + return G_IO_ERROR_CONNECTION_REFUSED; + break; +#endif + #ifdef ECONNRESET case ECONNRESET: return G_IO_ERROR_CONNECTION_CLOSED; diff --git a/gio/tests/error.c b/gio/tests/error.c index 702c9c651..7265fd284 100644 --- a/gio/tests/error.c +++ b/gio/tests/error.c @@ -572,7 +572,7 @@ test_error_from_errno (void) #ifdef EADDRNOTAVAIL g_assert_cmpuint (g_io_error_from_errno (EADDRNOTAVAIL), ==, - G_IO_ERROR_FAILED); + G_IO_ERROR_CONNECTION_REFUSED); #endif #ifdef ENETDOWN