Skip to content

Commit

Permalink
[Network] Make P/Invokes in NW*Descriptor and NWWebSocket* have blitt…
Browse files Browse the repository at this point in the history
…able signatures. (#20659)

Contributes towards #15684.
  • Loading branch information
rolfbjarne authored May 29, 2024
1 parent eaae1ae commit 1c7604c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
9 changes: 4 additions & 5 deletions src/Network/NWAdvertiseDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,14 @@ public void SetTxtRecord (string txt)
}

[DllImport (Constants.NetworkLibrary)]
static extern void nw_advertise_descriptor_set_no_auto_rename (IntPtr handle, [MarshalAs (UnmanagedType.I1)] bool no_auto_rename);
static extern void nw_advertise_descriptor_set_no_auto_rename (IntPtr handle, byte no_auto_rename);

[DllImport (Constants.NetworkLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool nw_advertise_descriptor_get_no_auto_rename (IntPtr handle);
static extern byte nw_advertise_descriptor_get_no_auto_rename (IntPtr handle);

public bool NoAutoRename {
set => nw_advertise_descriptor_set_no_auto_rename (GetCheckedHandle (), value);
get => nw_advertise_descriptor_get_no_auto_rename (GetCheckedHandle ());
set => nw_advertise_descriptor_set_no_auto_rename (GetCheckedHandle (), value.AsByte ());
get => nw_advertise_descriptor_get_no_auto_rename (GetCheckedHandle ()) != 0;
}

#if NET
Expand Down
9 changes: 4 additions & 5 deletions src/Network/NWBrowserDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@ public static NWBrowserDescriptor CreateBonjourService (string type, string? dom
public static NWBrowserDescriptor CreateBonjourService (string type) => CreateBonjourService (type, null);

[DllImport (Constants.NetworkLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool nw_browse_descriptor_get_include_txt_record (OS_nw_browse_descriptor descriptor);
static extern byte nw_browse_descriptor_get_include_txt_record (OS_nw_browse_descriptor descriptor);

[DllImport (Constants.NetworkLibrary)]
static extern void nw_browse_descriptor_set_include_txt_record (OS_nw_browse_descriptor descriptor, [MarshalAs (UnmanagedType.I1)] bool include_txt_record);
static extern void nw_browse_descriptor_set_include_txt_record (OS_nw_browse_descriptor descriptor, byte include_txt_record);

public bool IncludeTxtRecord {
get => nw_browse_descriptor_get_include_txt_record (GetCheckedHandle ());
set => nw_browse_descriptor_set_include_txt_record (GetCheckedHandle (), value);
get => nw_browse_descriptor_get_include_txt_record (GetCheckedHandle ()) != 0;
set => nw_browse_descriptor_set_include_txt_record (GetCheckedHandle (), value.AsByte ());
}

[DllImport (Constants.NetworkLibrary, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
Expand Down
8 changes: 4 additions & 4 deletions src/Network/NWWebSocketOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ public void AddSubprotocol (string subprotocol)
}

[DllImport (Constants.NetworkLibrary)]
static extern void nw_ws_options_set_auto_reply_ping (OS_nw_protocol_options options, [MarshalAs (UnmanagedType.I1)] bool auto_reply_ping);
static extern void nw_ws_options_set_auto_reply_ping (OS_nw_protocol_options options, byte auto_reply_ping);

public bool AutoReplyPing {
get { return autoReplyPing; }
set {
autoReplyPing = value;
nw_ws_options_set_auto_reply_ping (GetCheckedHandle (), value);
nw_ws_options_set_auto_reply_ping (GetCheckedHandle (), value.AsByte ());
}
}

Expand All @@ -94,13 +94,13 @@ public nuint MaximumMessageSize {
}

[DllImport (Constants.NetworkLibrary)]
static extern void nw_ws_options_set_skip_handshake (OS_nw_protocol_options options, [MarshalAs (UnmanagedType.I1)] bool skip_handshake);
static extern void nw_ws_options_set_skip_handshake (OS_nw_protocol_options options, byte skip_handshake);

public bool SkipHandShake {
get { return skipHandShake; }
set {
skipHandShake = value;
nw_ws_options_set_skip_handshake (GetCheckedHandle (), value);
nw_ws_options_set_skip_handshake (GetCheckedHandle (), value.AsByte ());
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/Network/NWWebSocketRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class NWWebSocketRequest : NativeObject {
internal NWWebSocketRequest (NativeHandle handle, bool owns) : base (handle, owns) { }

[DllImport (Constants.NetworkLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
unsafe static extern bool nw_ws_request_enumerate_additional_headers (OS_nw_ws_request request, BlockLiteral* enumerator);
unsafe static extern byte nw_ws_request_enumerate_additional_headers (OS_nw_ws_request request, BlockLiteral* enumerator);

#if !NET
delegate void nw_ws_request_enumerate_additional_headers_t (IntPtr block, IntPtr header, IntPtr value);
Expand Down Expand Up @@ -79,8 +78,7 @@ public void EnumerateAdditionalHeaders (Action<string?, string?> handler)
}

[DllImport (Constants.NetworkLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
unsafe static extern bool nw_ws_request_enumerate_subprotocols (OS_nw_ws_request request, BlockLiteral* enumerator);
unsafe static extern byte nw_ws_request_enumerate_subprotocols (OS_nw_ws_request request, BlockLiteral* enumerator);

#if !NET
delegate void nw_ws_request_enumerate_subprotocols_t (IntPtr block, IntPtr subprotocol);
Expand Down
5 changes: 2 additions & 3 deletions src/Network/NWWebSocketResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ static string nw_ws_response_get_selected_subprotocol (OS_nw_ws_response respons
public NWWebSocketResponseStatus Status => nw_ws_response_get_status (GetCheckedHandle ());

[DllImport (Constants.NetworkLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
unsafe static extern bool nw_ws_response_enumerate_additional_headers (OS_nw_ws_response response, BlockLiteral* enumerator);
unsafe static extern byte nw_ws_response_enumerate_additional_headers (OS_nw_ws_response response, BlockLiteral* enumerator);

#if !NET
delegate void nw_ws_response_enumerate_additional_headers_t (IntPtr block, IntPtr header, IntPtr value);
Expand Down Expand Up @@ -103,7 +102,7 @@ public bool EnumerateAdditionalHeaders (Action<string?, string?> handler)
using var block = new BlockLiteral ();
block.SetupBlockUnsafe (static_EnumerateHeadersHandler, handler);
#endif
return nw_ws_response_enumerate_additional_headers (GetCheckedHandle (), &block);
return nw_ws_response_enumerate_additional_headers (GetCheckedHandle (), &block) != 0;
}
}

Expand Down
9 changes: 0 additions & 9 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +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.NWAdvertiseDescriptor::nw_advertise_descriptor_get_no_auto_rename(System.IntPtr)",
"System.Boolean Network.NWBrowserDescriptor::nw_browse_descriptor_get_include_txt_record(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)",
Expand All @@ -54,15 +52,10 @@ public partial class BlittablePInvokes {
"System.Boolean Network.NWTxtRecord::nw_txt_record_access_key(System.IntPtr,System.IntPtr,ObjCRuntime.BlockLiteral*)",
"System.Boolean Network.NWTxtRecord::nw_txt_record_apply(System.IntPtr,ObjCRuntime.BlockLiteral*)",
"System.Boolean Network.NWTxtRecord::nw_txt_record_is_equal(System.IntPtr,System.IntPtr)",
"System.Boolean Network.NWWebSocketRequest::nw_ws_request_enumerate_additional_headers(System.IntPtr,ObjCRuntime.BlockLiteral*)",
"System.Boolean Network.NWWebSocketRequest::nw_ws_request_enumerate_subprotocols(System.IntPtr,ObjCRuntime.BlockLiteral*)",
"System.Boolean Network.NWWebSocketResponse::nw_ws_response_enumerate_additional_headers(System.IntPtr,ObjCRuntime.BlockLiteral*)",
"System.Byte* Network.NWEndpoint::nw_endpoint_get_signature(System.IntPtr,System.UIntPtr&)",
"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.NWAdvertiseDescriptor::nw_advertise_descriptor_set_no_auto_rename(System.IntPtr,System.Boolean)",
"System.Void Network.NWBrowserDescriptor::nw_browse_descriptor_set_include_txt_record(System.IntPtr,System.Boolean)",
"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)",
Expand All @@ -76,8 +69,6 @@ public partial class BlittablePInvokes {
"System.Void Network.NWParameters::nw_parameters_set_requires_dnssec_validation(System.IntPtr,System.Boolean)",
"System.Void Network.NWParameters::nw_parameters_set_reuse_local_address(System.IntPtr,System.Boolean)",
"System.Void Network.NWPrivacyContext::nw_privacy_context_require_encrypted_name_resolution(System.IntPtr,System.Boolean,System.IntPtr)",
"System.Void Network.NWWebSocketOptions::nw_ws_options_set_auto_reply_ping(System.IntPtr,System.Boolean)",
"System.Void Network.NWWebSocketOptions::nw_ws_options_set_skip_handshake(System.IntPtr,System.Boolean)",
"System.Void ObjCRuntime.Messaging::void_objc_msgSend_GCDualSenseAdaptiveTriggerPositionalAmplitudes_float(System.IntPtr,System.IntPtr,GameController.GCDualSenseAdaptiveTriggerPositionalAmplitudes,System.Single)",
"System.Void ObjCRuntime.Messaging::void_objc_msgSend_GCDualSenseAdaptiveTriggerPositionalResistiveStrengths(System.IntPtr,System.IntPtr,GameController.GCDualSenseAdaptiveTriggerPositionalResistiveStrengths)",
"System.Void ObjCRuntime.Messaging::void_objc_msgSendSuper_GCDualSenseAdaptiveTriggerPositionalAmplitudes_float(System.IntPtr,System.IntPtr,GameController.GCDualSenseAdaptiveTriggerPositionalAmplitudes,System.Single)",
Expand Down

12 comments on commit 1c7604c

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

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