diff --git a/src/Network/NWEnums.cs b/src/Network/NWEnums.cs index 494e9643ea..34ea8aa327 100644 --- a/src/Network/NWEnums.cs +++ b/src/Network/NWEnums.cs @@ -175,6 +175,8 @@ namespace Network { Default = 0, Allow = 1, Prohibit = 2, + [Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] + Persistent = 3, } // this maps to `nw_path_status_t` in Network/Headers/path.h (and not the enum from NetworkExtension) diff --git a/src/Network/NWListener.cs b/src/Network/NWListener.cs index 0101ed70d9..22b3625286 100644 --- a/src/Network/NWListener.cs +++ b/src/Network/NWListener.cs @@ -96,6 +96,35 @@ namespace Network { return new NWListener (handle, owns: true); } +#if __MACOS__ && NET + [SupportedOSPlatform ("macos")] + [UnsupportedOSPlatform ("tvos")] + [UnsupportedOSPlatform ("ios")] + [UnsupportedOSPlatform ("maccatalyst")] + [DllImport (Constants.NetworkLibrary)] + extern static IntPtr nw_listener_create_with_launchd_key (/* nw_parameters_t */ IntPtr nwparameters, /* const char */ IntPtr launchd_key); + + /// Creates an instance from a launchd key. + /// The parameters to use for the listener, including the protocols to use. + /// The name of the socket entry as specified in the launchd.plist. + /// A new instance, or null if not successful. + [SupportedOSPlatform ("macos")] + [UnsupportedOSPlatform ("tvos")] + [UnsupportedOSPlatform ("ios")] + [UnsupportedOSPlatform ("maccatalyst")] + public static NWListener? Create (NWParameters parameters, string launchd_key) + { + if (launchd_key is null) + ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (launchd_key)); + + using var launchd_key_ptr = new TransientString (launchd_key); + var handle = nw_listener_create_with_launchd_key (parameters.GetNonNullHandle (nameof (parameters)), launchd_key_ptr); + if (handle == IntPtr.Zero) + return null; + return new NWListener (handle, owns: true); + } +#endif // __MACOS__ && NET + [DllImport (Constants.NetworkLibrary)] extern static void nw_listener_set_queue (IntPtr listener, IntPtr queue); diff --git a/src/Network/NWQuicMetadata.cs b/src/Network/NWQuicMetadata.cs index 7e2938af10..d3512af9f6 100644 --- a/src/Network/NWQuicMetadata.cs +++ b/src/Network/NWQuicMetadata.cs @@ -54,6 +54,15 @@ namespace Network { set => nw_quic_set_keepalive_interval (GetCheckedHandle (), value); } + /// + /// Set the default keepalive value. The current default is every 20 seconds, but this is subject to change. + /// + public void SetDefaultKeepAlive () + { + // #define NW_QUIC_CONNECTION_DEFAULT_KEEPALIVE UINT16_MAX + KeepaliveInterval = ushort.MaxValue; + } + [DllImport (Constants.NetworkLibrary, EntryPoint = "nw_quic_get_application_error_reason")] static extern IntPtr nw_quic_get_application_error_reason_ptr (OS_nw_protocol_metadata metadata); diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt index 4e22680b43..1d3e8ef930 100644 --- a/tests/cecil-tests/Documentation.KnownFailures.txt +++ b/tests/cecil-tests/Documentation.KnownFailures.txt @@ -15538,6 +15538,7 @@ F:Network.NWParametersAttribution.Developer F:Network.NWParametersAttribution.User F:Network.NWParametersExpiredDnsBehavior.Allow F:Network.NWParametersExpiredDnsBehavior.Default +F:Network.NWParametersExpiredDnsBehavior.Persistent F:Network.NWParametersExpiredDnsBehavior.Prohibit F:Network.NWPathStatus.Invalid F:Network.NWPathStatus.Satisfiable diff --git a/tests/monotouch-test/Network/NWListenerTest.cs b/tests/monotouch-test/Network/NWListenerTest.cs index ae99ba4196..f6c626bef9 100644 --- a/tests/monotouch-test/Network/NWListenerTest.cs +++ b/tests/monotouch-test/Network/NWListenerTest.cs @@ -61,6 +61,16 @@ namespace MonoTouchFixtures.Network { }); }); } + +#if __MACOS__ && NET + [Test] + public void TestCreateLaunchd () + { + using var parameters = NWParameters.CreateTcp (); + using var instance = NWListener.Create (parameters, "xamarinlaunchdkey"); + Assert.IsNotNull (instance, "Create"); + } +#endif } } #endif diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-Network.todo b/tests/xtro-sharpie/api-annotations-dotnet/macOS-Network.todo deleted file mode 100644 index 90e2bbc0ca..0000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-Network.todo +++ /dev/null @@ -1 +0,0 @@ -!missing-pinvoke! nw_listener_create_with_launchd_key is not bound