From b2a5fd41994485fb6dd9a8085d35fa97736856cd Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 4 Sep 2024 23:14:07 +0200 Subject: [PATCH] [Network] Fix binding mistake in NWConnection. (#21174) The 'nw_connection_set_viability_changed_handler' P/Invoke was originally bound as 'SetBooleanChangeHandler', which isn't quite right. So now bind it as 'SetViabilityChangeHandler', obsolete the old version and remove it in XAMCORE_5_0. --- src/Network/NWConnection.cs | 13 +++++++++++++ tests/cecil-tests/Documentation.KnownFailures.txt | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Network/NWConnection.cs b/src/Network/NWConnection.cs index ed153271bb9a..f68baf330bb2 100644 --- a/src/Network/NWConnection.cs +++ b/src/Network/NWConnection.cs @@ -9,6 +9,7 @@ #nullable enable using System; +using System.ComponentModel; using System.Runtime.InteropServices; using ObjCRuntime; using Foundation; @@ -157,8 +158,20 @@ static void TrampolineBooleanChangeHandler (IntPtr block, byte value) [DllImport (Constants.NetworkLibrary)] static extern unsafe void nw_connection_set_viability_changed_handler (IntPtr handle, void* callback); +#if !XAMCORE_5_0 + [Obsolete ("Use 'SetViabilityChangeHandler' instead.")] + [EditorBrowsable (EditorBrowsableState.Never)] [BindingImpl (BindingImplOptions.Optimizable)] public unsafe void SetBooleanChangeHandler (Action callback) + { + SetViabilityChangeHandler (callback); + } +#endif // !XAMCORE_5_0 + + /// Set a handler that is called when data can be sent or received. + /// The callback to call when data can be sent or received. + [BindingImpl (BindingImplOptions.Optimizable)] + public unsafe void SetViabilityChangeHandler (Action callback) { if (callback is null) { nw_connection_set_viability_changed_handler (GetCheckedHandle (), null); diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt index d865eab4c8bf..bb122cdc876a 100644 --- a/tests/cecil-tests/Documentation.KnownFailures.txt +++ b/tests/cecil-tests/Documentation.KnownFailures.txt @@ -42193,7 +42193,6 @@ M:Network.NWConnection.Send(System.Byte[],System.Int32,System.Int32,Network.NWCo M:Network.NWConnection.SendIdempotent(CoreFoundation.DispatchData,Network.NWContentContext,System.Boolean) M:Network.NWConnection.SendIdempotent(System.Byte[],Network.NWContentContext,System.Boolean) M:Network.NWConnection.SetBetterPathAvailableHandler(System.Action{System.Boolean}) -M:Network.NWConnection.SetBooleanChangeHandler(System.Action{System.Boolean}) M:Network.NWConnection.SetPathChangedHandler(System.Action{Network.NWPath}) M:Network.NWConnection.SetQueue(CoreFoundation.DispatchQueue) M:Network.NWConnection.SetStateChangeHandler(System.Action{Network.NWConnectionState,Network.NWError})