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] Add support for Xcode 14 beta 6. #15841

Merged
merged 10 commits into from
Sep 8, 2022
59 changes: 59 additions & 0 deletions src/Network/NWAdvertiseDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,65 @@ public NWAdvertiseDescriptor (NativeHandle handle, bool owns) : base (handle, ow
#endif
{ }

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern OS_nw_advertise_descriptor nw_advertise_descriptor_create_application_service (string application_service_name);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
public NWAdvertiseDescriptor (string applicationServiceName) : base (nw_advertise_descriptor_create_application_service (applicationServiceName), true) {}

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern IntPtr nw_advertise_descriptor_get_application_service_name (OS_nw_advertise_descriptor advertise_descriptor);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
public string? ApplicationServiceName {
get {
var appNamePtr = nw_advertise_descriptor_get_application_service_name (GetCheckedHandle ());
return Marshal.PtrToStringAnsi (appNamePtr);
}
}

[DllImport (Constants.NetworkLibrary)]
static extern IntPtr nw_advertise_descriptor_create_bonjour_service (string name, string type, string? domain);

Expand Down
65 changes: 65 additions & 0 deletions src/Network/NWBrowserDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,71 @@ internal NWBrowserDescriptor (NativeHandle handle, bool owns) : base (handle, ow
[DllImport (Constants.NetworkLibrary)]
static extern OS_nw_browse_descriptor nw_browse_descriptor_create_bonjour_service (string type, string? domain);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern OS_nw_browse_descriptor nw_browse_descriptor_create_application_service (string application_service_name);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
public static NWBrowserDescriptor CreateApplicationServiceName (string applicationServiceName)
{
if (applicationServiceName is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (applicationServiceName));

return new NWBrowserDescriptor (nw_browse_descriptor_create_application_service (applicationServiceName), owns: true);
}

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern IntPtr nw_browse_descriptor_get_application_service_name (OS_nw_browse_descriptor descriptor);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
public string? ApplicationServiceName {
get {
var appNamePtr = nw_browse_descriptor_get_application_service_name (GetCheckedHandle ());
return Marshal.PtrToStringAnsi (appNamePtr);
}
}

public static NWBrowserDescriptor CreateBonjourService (string type, string? domain)
{
// domain can be null, type CANNOT
Expand Down
72 changes: 72 additions & 0 deletions src/Network/NWEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using CoreFoundation;

using OS_nw_endpoint=System.IntPtr;
using OS_nw_txt_record=System.IntPtr;

#if !NET
using NativeHandle = System.IntPtr;
Expand Down Expand Up @@ -183,5 +184,76 @@ public NWEndpoint (NativeHandle handle, bool owns) : base (handle, owns) {}
[iOS (13,0)]
#endif
public string? Url => Marshal.PtrToStringAnsi (nw_endpoint_get_url (GetCheckedHandle ()));


#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern unsafe byte* nw_endpoint_get_signature (OS_nw_endpoint endpoint, out nuint out_signature_length);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
public ReadOnlySpan<byte> Signature {
get {
unsafe {
var data = nw_endpoint_get_signature (GetCheckedHandle (), out var length);
var mValue = new ReadOnlySpan<byte> (data, (int)length);
return mValue;
}
}
}

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern OS_nw_txt_record nw_endpoint_copy_txt_record (OS_nw_endpoint endpoint);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[Watch (9,0)]
#endif
public NWTxtRecord? TxtRecord {
get {
var record = nw_endpoint_copy_txt_record (GetCheckedHandle ());
if (record == IntPtr.Zero)
return null;
return new NWTxtRecord (record, owns: true);
}
}

}
}
9 changes: 9 additions & 0 deletions src/Network/NWEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public enum NWEndpointType {
Address = 1,
Host = 2,
BonjourService = 3,
[TV (13,0), Mac (10,15), iOS (13,0), Watch (6,0)]
Url = 4,
}

[TV (13,0), Mac (10,15), iOS (13,0), Watch (6,0)]
Expand Down Expand Up @@ -283,4 +285,11 @@ public enum NWParametersAttribution {
Developer = 1,
User = 2,
}

[Watch (8,0), TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
public enum NWQuicStreamType {
Unknown = 0,
Bidirectional = 1,
Unidirectional = 2,
}
}
54 changes: 54 additions & 0 deletions src/Network/NWEthernetChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using OS_nw_ethernet_channel=System.IntPtr;
using OS_nw_interface=System.IntPtr;
using OS_dispatch_data=System.IntPtr;
using OS_nw_parameters=System.IntPtr;


#if !NET
using NativeHandle = System.IntPtr;
Expand Down Expand Up @@ -76,6 +78,33 @@ public NWEthernetChannel (ushort ethernetType, NWInterface networkInterface)
InitializeHandle (nw_ethernet_channel_create (ethernetType, networkInterface.Handle));
}

#if NET
[SupportedOSPlatform ("macos13.0")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("ios")]
#else
[NoWatch]
[NoTV]
[NoiOS]
[Mac (13,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern OS_nw_ethernet_channel nw_ethernet_channel_create_with_parameters (ushort ether_type, OS_nw_interface @interface, OS_nw_parameters parameters);

#if NET
[SupportedOSPlatform ("macos13.0")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("ios")]
#else
[NoWatch]
[NoTV]
[NoiOS]
[Mac (13,0)]
#endif
public NWEthernetChannel (ushort ethernetType, NWInterface networkInterface, NWParameters parameters) =>
InitializeHandle (nw_ethernet_channel_create_with_parameters (ethernetType,
networkInterface.GetNonNullHandle (nameof (networkInterface)), parameters.GetNonNullHandle (nameof (parameters))));

[DllImport (Constants.NetworkLibrary)]
static extern void nw_ethernet_channel_start (OS_nw_ethernet_channel ethernet_channel);

Expand Down Expand Up @@ -202,6 +231,31 @@ public void SetStateChangesHandler (Action<NWBrowserState, NWError?> handler)
}
}
}

#if NET
[SupportedOSPlatform ("macos13.0")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("ios")]
#else
[NoWatch]
[NoTV]
[NoiOS]
[Mac (13,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern uint nw_ethernet_channel_get_maximum_payload_size (OS_nw_ethernet_channel ethernet_channel);

#if NET
[SupportedOSPlatform ("macos13.0")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("ios")]
#else
[NoWatch]
[NoTV]
[NoiOS]
[Mac (13,0)]
#endif
public uint MaximumPayloadSize => nw_ethernet_channel_get_maximum_payload_size (GetCheckedHandle ());
}
}
#endif
36 changes: 36 additions & 0 deletions src/Network/NWFramer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,41 @@ public void DeliverInput (ReadOnlySpan<byte> buffer, NWFramerMessage message, bo
nw_framer_deliver_input (GetCheckedHandle (),mh, (nuint)buffer.Length, message.Handle, isComplete);
}
}

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[MacCatalyst (16,0)]
[Watch (9,0)]
#endif
[DllImport (Constants.NetworkLibrary)]
static extern OS_nw_protocol_options nw_framer_copy_options (OS_nw_framer framer);

#if NET
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[TV (16,0)]
[Mac (13,0)]
[iOS (16,0)]
[MacCatalyst (16,0)]
[Watch (9,0)]
#endif
public NSProtocolFramerOptions? ProtocolOptions {
get {
var x = nw_framer_copy_options (GetCheckedHandle ());
if (x == IntPtr.Zero)
return null;
return new NSProtocolFramerOptions (x, owns: true);
}
}
}
}
Loading