gioerror: Map EADDRNOTAVAIL to G_IO_ERROR_CONNECTION_REFUSED

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 <pwithnall@gnome.org>

See: #3184
Fixes: #3394
This commit is contained in:
Philip Withnall 2024-06-13 19:54:45 +01:00
parent ea58dcb538
commit f09a8e2be4
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73
2 changed files with 7 additions and 1 deletions

View File

@ -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;

View File

@ -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