Skip to content

Commit

Permalink
[Network] Update to Xcode 10 beta 3. (#4686)
Browse files Browse the repository at this point in the history
Adds the new functions added in beta 3 and cleans some of the xtro
files.
  • Loading branch information
mandel-macaque authored and spouliot committed Aug 28, 2018
1 parent 20edb35 commit 2838b98
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 163 deletions.
2 changes: 1 addition & 1 deletion src/Network/NWAdvertiseDescriptor.cs
Expand Up @@ -16,7 +16,7 @@
using OS_nw_advertise_descriptor=System.IntPtr;

namespace Network {
[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWAdvertiseDescriptor : NativeObject {
public NWAdvertiseDescriptor (IntPtr handle, bool owns) : base (handle, owns)
{ }
Expand Down
14 changes: 2 additions & 12 deletions src/Network/NWConnection.cs
Expand Up @@ -40,7 +40,7 @@ public enum NWConnectionState {
//
public delegate void NWConnectionReceiveDispatchDataCompletion (DispatchData data, NWContentContext context, bool isComplete, NWError error);

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWConnection : NativeObject {
public NWConnection (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down Expand Up @@ -440,22 +440,12 @@ public void Send (DispatchData buffer, NWContentContext context, bool isComplete
}
}

static IntPtr _nw_connection_send_idempotent_content;

// This is a special token handled by the library that configures the Send operation to be idempotent.
static IntPtr NW_CONNECTION_SEND_IDEMPOTENT_CONTENT ()
{
if (_nw_connection_send_idempotent_content == IntPtr.Zero)
_nw_connection_send_idempotent_content = Marshal.ReadIntPtr (Dlfcn.dlsym (Libraries.Network.Handle, "_nw_connection_send_idempotent_content"));
return _nw_connection_send_idempotent_content;
}

public unsafe void SendIdempotent (DispatchData buffer, NWContentContext context, bool isComplete)
{
if (context == null)
throw new ArgumentNullException (nameof (context));

LowLevelSend (GetCheckedHandle (), buffer, context.Handle, isComplete, (void *) NW_CONNECTION_SEND_IDEMPOTENT_CONTENT ());
LowLevelSend (GetCheckedHandle (), buffer, context.Handle, isComplete, (void *) NWConnectionConstants._SendIdempotentContent);
}

public void SendIdempotent (byte [] buffer, NWContentContext context, bool isComplete)
Expand Down
8 changes: 4 additions & 4 deletions src/Network/NWContentContext.cs
Expand Up @@ -18,7 +18,7 @@ namespace Network {
// The content context, there are a few pre-configured content contexts for sending
// available as static properties on this class
//
[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWContentContext : NativeObject {
bool global;
public NWContentContext (IntPtr handle, bool owns) : base (handle, owns)
Expand Down Expand Up @@ -176,7 +176,7 @@ public void IterateProtocolMetadata (Action<NWProtocolDefinition,NWProtocolMetad
public static NWContentContext DefaultMessage {
get {
if (defaultMessage == null)
defaultMessage = MakeGlobal (Marshal.ReadIntPtr (Dlfcn.dlsym (Libraries.Network.Handle, "_nw_content_context_default_message")));
defaultMessage = MakeGlobal (NWContentContextConstants._DefaultMessage);

return defaultMessage;
}
Expand All @@ -188,7 +188,7 @@ public void IterateProtocolMetadata (Action<NWProtocolDefinition,NWProtocolMetad
public static NWContentContext FinalMessage {
get {
if (finalMessage == null)
finalMessage = MakeGlobal (Marshal.ReadIntPtr (Dlfcn.dlsym (Libraries.Network.Handle, "_nw_content_context_final_send")));
finalMessage = MakeGlobal (NWContentContextConstants._FinalSend);
return finalMessage;
}
}
Expand All @@ -199,7 +199,7 @@ public void IterateProtocolMetadata (Action<NWProtocolDefinition,NWProtocolMetad
public static NWContentContext DefaultStream {
get {
if (defaultStream == null)
defaultStream = MakeGlobal (Marshal.ReadIntPtr (Dlfcn.dlsym (Libraries.Network.Handle, "_nw_content_context_default_stream")));
defaultStream = MakeGlobal (NWContentContextConstants._DefaultStream);
return defaultStream;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Network/NWEndpoint.cs
Expand Up @@ -24,7 +24,7 @@ public enum NWEndpointType {
BonjourService = 3,
}

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWEndpoint : NativeObject {
public NWEndpoint (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down
9 changes: 1 addition & 8 deletions src/Network/NWError.cs
Expand Up @@ -14,14 +14,7 @@
using CoreFoundation;

namespace Network {
public enum NWErrorDomain {
Invalid = 0,
Posix = 1,
Dns = 2,
Tls = 3,
}

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWError : NativeObject {
public NWError (IntPtr handle, bool owns) : base (handle, owns)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Network/NWInterface.cs
Expand Up @@ -17,7 +17,7 @@

namespace Network {

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWInterface : NativeObject {
public NWInterface (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down
2 changes: 1 addition & 1 deletion src/Network/NWListener.cs
Expand Up @@ -21,7 +21,7 @@ public enum NWListenerState {
Cancelled = 4,
}

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWListener : NativeObject {
public NWListener (IntPtr handle, bool owns) : base (handle, owns)
{
Expand Down
33 changes: 16 additions & 17 deletions src/Network/NWParameters.cs
Expand Up @@ -29,27 +29,13 @@ static public class Network {
}
}

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWParameters : NativeObject {
public NWParameters (IntPtr handle, bool owns) : base (handle, owns) {}

static IntPtr _nw_parameters_configure_protocol_default_configuration;
static unsafe BlockLiteral *DEFAULT_CONFIGURATION () => (BlockLiteral *) NWParametersConstants._DefaultConfiguration;

static unsafe BlockLiteral *DEFAULT_CONFIGURATION ()
{
if (_nw_parameters_configure_protocol_default_configuration == IntPtr.Zero)
_nw_parameters_configure_protocol_default_configuration = Marshal.ReadIntPtr (Dlfcn.dlsym (Libraries.Network.Handle, "_nw_parameters_configure_protocol_default_configuration"));

return (BlockLiteral *) _nw_parameters_configure_protocol_default_configuration;
}

static IntPtr _nw_parameters_configure_protocol_disable;
static unsafe BlockLiteral *DISABLE_PROTOCOL ()
{
if (_nw_parameters_configure_protocol_disable == IntPtr.Zero)
_nw_parameters_configure_protocol_disable = Marshal.ReadIntPtr (Dlfcn.dlsym (Libraries.Network.Handle, "_nw_parameters_configure_protocol_disable"));
return (BlockLiteral *) _nw_parameters_configure_protocol_disable;
}
static unsafe BlockLiteral *DISABLE_PROTOCOL () => (BlockLiteral *) NWParametersConstants._ProtocolDisable;

delegate void nw_parameters_configure_protocol_block_t (IntPtr block, IntPtr iface);
static nw_parameters_configure_protocol_block_t static_ConfigureHandler = TrampolineConfigureHandler;
Expand Down Expand Up @@ -441,6 +427,19 @@ public void IterateProhibitedInterfaces (Func<NWInterfaceType,bool> callback)
nw_parameters_set_local_endpoint (GetCheckedHandle (), value.GetHandle ());
}
}


[DllImport (Constants.NetworkLibrary)]
static extern void nw_parameters_set_include_peer_to_peer (IntPtr handle, bool includePeerToPeer);

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

public bool IncludePeerToPeer {
get => nw_parameters_get_include_peer_to_peer (GetCheckedHandle ());
set => nw_parameters_set_include_peer_to_peer (GetCheckedHandle (), value);
}
}

public enum NWParametersExpiredDnsBehavior {
Expand Down
5 changes: 4 additions & 1 deletion src/Network/NWPath.cs
Expand Up @@ -14,14 +14,17 @@
using CoreFoundation;

namespace Network {

// this maps to `nw_path_status_t` in Network/Headers/path.h (and not the enum from NetworkExtension)
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public enum NWPathStatus {
Invalid = 0,
Satisfied = 1,
Unsatisfied = 2,
Satisfiable = 3,
}

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWPath : NativeObject {
public NWPath (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down
2 changes: 1 addition & 1 deletion src/Network/NWPathMonitor.cs
Expand Up @@ -15,7 +15,7 @@

namespace Network {

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWPathMonitor : NativeObject {
public NWPathMonitor (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down
2 changes: 1 addition & 1 deletion src/Network/NWProtocolDefinition.cs
Expand Up @@ -23,7 +23,7 @@ public enum NWIPVersion {
Version6 = 2,
}

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWProtocolDefinition : NativeObject {
public NWProtocolDefinition (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down
19 changes: 14 additions & 5 deletions src/Network/NWProtocolMetadata.cs
Expand Up @@ -35,12 +35,9 @@ public enum NWIPEcnFlag {
Ce = 3,
}

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWProtocolMetadata : NativeObject {

#if false
// Officially listed on header files, but seems to not work on Mac/iOS
// https://bugreport.apple.com/web/?problemID=42443077
[DllImport (Constants.NetworkLibrary)]
static extern OS_nw_protocol_metadata nw_ip_create_metadata ();

Expand All @@ -55,7 +52,6 @@ public static NWProtocolMetadata CreateUDPMetadata ()
{
return new NWProtocolMetadata (nw_udp_create_metadata (), owns: true);
}
#endif

public NWProtocolMetadata (IntPtr handle, bool owns) : base (handle, owns) {}

Expand All @@ -82,6 +78,12 @@ public static NWProtocolMetadata CreateUDPMetadata ()

public bool IsTls => nw_protocol_metadata_is_tls (GetCheckedHandle ());

[DllImport (Constants.NetworkLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool nw_protocol_metadata_is_tcp (OS_nw_protocol_metadata metadata);

public bool IsTcp => nw_protocol_metadata_is_tcp (GetCheckedHandle ());

[DllImport (Constants.NetworkLibrary)]
static extern IntPtr nw_tls_copy_sec_protocol_metadata (IntPtr handle);

Expand All @@ -98,6 +100,13 @@ public static NWProtocolMetadata CreateUDPMetadata ()
set => nw_ip_metadata_set_ecn_flag (GetCheckedHandle (), value);
}

[DllImport (Constants.NetworkLibrary)]
static extern /* uint64_t */ ulong nw_ip_metadata_get_receive_time (OS_nw_protocol_metadata metadata);

public ulong IPMetadataReceiveTime {
get => nw_ip_metadata_get_receive_time (GetCheckedHandle ());
}

[DllImport (Constants.NetworkLibrary)]
static extern void nw_ip_metadata_set_service_class (OS_nw_protocol_metadata metadata, NWServiceClass service_class);

Expand Down
10 changes: 9 additions & 1 deletion src/Network/NWProtocolOptions.cs
Expand Up @@ -18,7 +18,7 @@

namespace Network {

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWProtocolOptions : NativeObject {
public NWProtocolOptions (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down Expand Up @@ -86,6 +86,14 @@ public void IPSetDisableFragmentation (bool disableFragmentation)
nw_ip_options_set_disable_fragmentation (GetCheckedHandle (), disableFragmentation);
}

[DllImport (Constants.NetworkLibrary)]
static extern void nw_ip_options_set_calculate_receive_time (IntPtr options, bool calculateReceiveTime);

public void IPSetCalculateReceiveTime (bool calculateReceiveTime)
{
nw_ip_options_set_calculate_receive_time (GetCheckedHandle (), calculateReceiveTime);
}

//
// TCP Options
//
Expand Down
2 changes: 1 addition & 1 deletion src/Network/NWProtocolStack.cs
Expand Up @@ -20,7 +20,7 @@

namespace Network {

[TV (12,0), Mac (10,14), iOS (12,0)]
[TV (12,0), Mac (10,14, onlyOn64: true), iOS (12,0)]
public class NWProtocolStack : NativeObject {
public NWProtocolStack (IntPtr handle, bool owns) : base (handle, owns) {}

Expand Down
55 changes: 55 additions & 0 deletions src/network.cs
@@ -0,0 +1,55 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using ObjCRuntime;
using Foundation;
using CoreFoundation;

namespace Network {

[TV (12,0), Mac (10,14 ,onlyOn64: true), iOS (12,0)]
public enum NWErrorDomain {
Invalid = 0,
[Field ("kNWErrorDomainPOSIX")]
Posix = 1,
[Field ("kNWErrorDomainDNS")]
Dns = 2,
[Field ("kNWErrorDomainTLS")]
Tls = 3,
}

[TV (12,0), Mac (10,14 ,onlyOn64: true), iOS (12,0)]
[Static]
[Internal]
partial interface NWContentContextConstants {
[Field ("_nw_content_context_default_message")]
IntPtr _DefaultMessage { get; }

[Field ("_nw_content_context_final_send")]
IntPtr _FinalSend { get; }

[Field ("_nw_content_context_default_stream")]
IntPtr _DefaultStream { get; }
}

[TV (12,0), Mac (10,14 ,onlyOn64: true), iOS (12,0)]
[Static]
[Internal]
partial interface NWConnectionConstants {

[Field ("_nw_connection_send_idempotent_content")]
IntPtr _SendIdempotentContent { get; }
}

[TV (12,0), Mac (10,14 ,onlyOn64: true), iOS (12,0)]
[Static]
[Internal]
partial interface NWParametersConstants {
[Field ("_nw_parameters_configure_protocol_default_configuration")]
IntPtr _DefaultConfiguration { get; }

[Field ("_nw_parameters_configure_protocol_disable")]
IntPtr _ProtocolDisable { get; }

}
}
21 changes: 21 additions & 0 deletions tests/xtro-sharpie/common-Network.ignore
@@ -0,0 +1,21 @@
# the following are binded manualy as NativeObject

!missing-protocol! OS_nw_advertise_descriptor not bound
!missing-protocol! OS_nw_connection not bound
!missing-protocol! OS_nw_content_context not bound
!missing-protocol! OS_nw_endpoint not bound
!missing-protocol! OS_nw_error not bound
!missing-protocol! OS_nw_interface not bound
!missing-protocol! OS_nw_listener not bound
!missing-protocol! OS_nw_parameters not bound
!missing-protocol! OS_nw_path not bound
!missing-protocol! OS_nw_path_monitor not bound
!missing-protocol! OS_nw_protocol_definition not bound
!missing-protocol! OS_nw_protocol_metadata not bound
!missing-protocol! OS_nw_protocol_options not bound
!missing-protocol! OS_nw_protocol_stack not bound
!missing-protocol! OS_nw_object not bound

# no need, please see comment: https://github.com/xamarin/xamarin-macios/pull/4251#issuecomment-410815837
!missing-pinvoke! nw_release is not bound
!missing-pinvoke! nw_retain is not bound

1 comment on commit 2838b98

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jenkins job (on internal Jenkins) succeeded

Build succeeded
API Diff (from stable)
API Diff (from PR only) (please review changes)
Generator Diff (please review changes)
Test run succeeded

Please sign in to comment.