Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Network] Make P/Invokes in NWConnection[Group] have blittable signatures. #20662

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Network/NWConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ static void TrampolineSendCompletion (IntPtr block, IntPtr error)
static extern unsafe void nw_connection_send (IntPtr handle,
IntPtr dispatchData,
IntPtr contentContext,
[MarshalAs (UnmanagedType.U1)] bool isComplete,
byte isComplete,
BlockLiteral* callback);

//
Expand All @@ -511,7 +511,7 @@ unsafe void LowLevelSend (IntPtr handle, DispatchData? buffer, IntPtr contentCon
nw_connection_send (handle: GetCheckedHandle (),
dispatchData: buffer.GetHandle (),
contentContext: contentContext,
isComplete: isComplete,
isComplete: isComplete.AsByte (),
callback: callback);
}

Expand Down
11 changes: 5 additions & 6 deletions src/Network/NWConnectionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void Send (DispatchData? content, NWEndpoint? endpoint, NWContentContext
}

[DllImport (Constants.NetworkLibrary)]
unsafe static extern void nw_connection_group_set_receive_handler (OS_nw_connection_group group, uint maximum_message_size, [MarshalAs (UnmanagedType.I1)] bool reject_oversized_messages, BlockLiteral* handler);
unsafe static extern void nw_connection_group_set_receive_handler (OS_nw_connection_group group, uint maximum_message_size, byte reject_oversized_messages, BlockLiteral* handler);

#if !NET
delegate void nw_connection_group_receive_handler_t (IntPtr block, IntPtr content, IntPtr context, byte isCompleted);
Expand All @@ -259,7 +259,7 @@ public void SetReceiveHandler (uint maximumMessageSize, bool rejectOversizedMess
{
unsafe {
if (handler is null) {
nw_connection_group_set_receive_handler (GetCheckedHandle (), maximumMessageSize, rejectOversizedMessages, null);
nw_connection_group_set_receive_handler (GetCheckedHandle (), maximumMessageSize, rejectOversizedMessages.AsByte (), null);
return;
}

Expand All @@ -270,7 +270,7 @@ public void SetReceiveHandler (uint maximumMessageSize, bool rejectOversizedMess
using var block = new BlockLiteral ();
block.SetupBlockUnsafe (static_ReceiveHandler, handler);
#endif
nw_connection_group_set_receive_handler (GetCheckedHandle (), maximumMessageSize, rejectOversizedMessages, &block);
nw_connection_group_set_receive_handler (GetCheckedHandle (), maximumMessageSize, rejectOversizedMessages.AsByte (), &block);
}
}

Expand Down Expand Up @@ -432,8 +432,7 @@ public void SetStateChangedHandler (NWConnectionGroupStateChangedDelegate handle
[MacCatalyst (15, 0)]
#endif
[DllImport (Constants.NetworkLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool nw_connection_group_reinsert_extracted_connection (OS_nw_connection_group group, OS_nw_connection connection);
static extern byte nw_connection_group_reinsert_extracted_connection (OS_nw_connection_group group, OS_nw_connection connection);

#if NET
[SupportedOSPlatform ("tvos15.0")]
Expand All @@ -451,7 +450,7 @@ public bool TryReinsertExtractedConnection (NWConnection connection)
{
if (connection is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (connection));
return nw_connection_group_reinsert_extracted_connection (GetCheckedHandle (), connection.Handle);
return nw_connection_group_reinsert_extracted_connection (GetCheckedHandle (), connection.Handle) != 0;
}

#if NET
Expand Down
3 changes: 0 additions & 3 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public partial class BlittablePInvokes {
"AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSend(System.IntPtr,System.IntPtr)",
"AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSendSuper_stret(System.IntPtr,System.IntPtr)",
"AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSendSuper(System.IntPtr,System.IntPtr)",
"System.Boolean Network.NWConnectionGroup::nw_connection_group_reinsert_extracted_connection(System.IntPtr,System.IntPtr)",
"System.Boolean Network.NWContentContext::nw_content_context_get_is_final(System.IntPtr)",
"System.Boolean Network.NWEstablishmentReport::nw_establishment_report_get_proxy_configured(System.IntPtr)",
"System.Boolean Network.NWEstablishmentReport::nw_establishment_report_get_used_proxy(System.IntPtr)",
Expand Down Expand Up @@ -56,8 +55,6 @@ public partial class BlittablePInvokes {
"System.Int32 AudioUnit.AUGraph::NewAUGraph(System.IntPtr&)",
"System.IntPtr ObjCRuntime.Selector::GetHandle(System.String)",
"System.IntPtr Security.SecKey::SecKeyCreateEncryptedData(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr&)",
"System.Void Network.NWConnection::nw_connection_send(System.IntPtr,System.IntPtr,System.IntPtr,System.Boolean,ObjCRuntime.BlockLiteral*)",
"System.Void Network.NWConnectionGroup::nw_connection_group_set_receive_handler(System.IntPtr,System.UInt32,System.Boolean,ObjCRuntime.BlockLiteral*)",
"System.Void Network.NWContentContext::nw_content_context_set_is_final(System.IntPtr,System.Boolean)",
"System.Void Network.NWMulticastGroup::nw_multicast_group_descriptor_set_disable_unicast_traffic(System.IntPtr,System.Boolean)",
"System.Void Network.NWParameters::nw_parameters_set_fast_open_enabled(System.IntPtr,System.Boolean)",
Expand Down
Loading