Skip to content

Commit

Permalink
[Network] Fix binding mistake in NWConnection. (#21174)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rolfbjarne committed Sep 4, 2024
1 parent a854ebe commit b2a5fd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Network/NWConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#nullable enable

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using ObjCRuntime;
using Foundation;
Expand Down Expand Up @@ -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<bool> callback)
{
SetViabilityChangeHandler (callback);
}
#endif // !XAMCORE_5_0

/// <summary>Set a handler that is called when data can be sent or received.</summary>
/// <param name="callback">The callback to call when data can be sent or received.</param>
[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe void SetViabilityChangeHandler (Action<bool> callback)
{
if (callback is null) {
nw_connection_set_viability_changed_handler (GetCheckedHandle (), null);
Expand Down
1 change: 0 additions & 1 deletion tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

7 comments on commit b2a5fd4

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.