From 648a4a6b6bc726a70e8906afd98bcfebb65c7be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 11 Jul 2022 14:54:14 +0200 Subject: [PATCH 01/17] Support NetworkInterface.GetIsNetworkAvailable on browser. --- .../Directory.Build.props | 1 - .../ref/System.Net.NetworkInformation.cs | 1 + .../src/System.Net.NetworkInformation.csproj | 14 +++++- .../IPGlobalPropertiesPal.Browser.cs | 10 +++++ .../NetworkAddressChange.Browser.cs | 44 +++++++++++++++++++ .../NetworkAddressChange.OSX.cs | 1 + .../NetworkAddressChange.Unix.cs | 1 + .../NetworkAddressChange.UnknownUnix.cs | 1 + .../NetworkAddressChange.Windows.cs | 1 + .../NetworkInterfacePal.Browser.cs | 25 +++++++++++ ...NetworkInformation.Functional.Tests.csproj | 1 - src/mono/wasm/runtime/exports.ts | 4 ++ src/mono/wasm/runtime/network-information.ts | 6 +++ 13 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalPropertiesPal.Browser.cs create mode 100644 src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs create mode 100644 src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs create mode 100644 src/mono/wasm/runtime/network-information.ts diff --git a/src/libraries/System.Net.NetworkInformation/Directory.Build.props b/src/libraries/System.Net.NetworkInformation/Directory.Build.props index ce244cbea56199..d68d22c1b917f8 100644 --- a/src/libraries/System.Net.NetworkInformation/Directory.Build.props +++ b/src/libraries/System.Net.NetworkInformation/Directory.Build.props @@ -3,6 +3,5 @@ Microsoft true - browser \ No newline at end of file diff --git a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs index df04b533cca1b0..3bdf55cd8e8769 100644 --- a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs @@ -337,6 +337,7 @@ public partial class NetworkChange public NetworkChange() { } [System.Runtime.Versioning.UnsupportedOSPlatform("illumos")] [System.Runtime.Versioning.UnsupportedOSPlatform("solaris")] + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler? NetworkAddressChanged { add { } remove { } } [System.Runtime.Versioning.UnsupportedOSPlatform("illumos")] [System.Runtime.Versioning.UnsupportedOSPlatform("solaris")] diff --git a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj index 37cb80afcfa429..a5fe8d4c87cd28 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj +++ b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj @@ -1,7 +1,7 @@ true - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent) + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent) @@ -27,7 +27,7 @@ - + @@ -159,6 +159,16 @@ + + + + + + + + + + diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalPropertiesPal.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalPropertiesPal.Browser.cs new file mode 100644 index 00000000000000..f68fb9a5446986 --- /dev/null +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalPropertiesPal.Browser.cs @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Net.NetworkInformation +{ + internal static class IPGlobalPropertiesPal + { + public static IPGlobalProperties GetIPGlobalProperties() => throw new PlatformNotSupportedException(); + } +} diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs new file mode 100644 index 00000000000000..34c774794387b9 --- /dev/null +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.Win32.SafeHandles; + +using System.ComponentModel; +using System.Collections.Generic; +using System.Net.Sockets; +using System.Runtime.Versioning; +using System.Threading; + +namespace System.Net.NetworkInformation +{ + public partial class NetworkChange + { + [UnsupportedOSPlatform("illumos")] + [UnsupportedOSPlatform("solaris")] + public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged + { + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); + } + + [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("illumos")] + [UnsupportedOSPlatform("solaris")] + public static event NetworkAddressChangedEventHandler? NetworkAddressChanged + { + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); + } + + [EditorBrowsableAttribute(EditorBrowsableState.Never)] + [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] + public NetworkChange() + { + } + + // Introduced for supporting design-time loading of System.Windows.dll + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] + public static void RegisterNetworkChange(NetworkChange nc) { } + } +} diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs index fbdd96ab0a0388..d1a5943863a2ba 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs @@ -39,6 +39,7 @@ public partial class NetworkChange private static readonly AutoResetEvent s_runLoopStartedEvent = new AutoResetEvent(false); private static readonly AutoResetEvent s_runLoopEndedEvent = new AutoResetEvent(false); + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static event NetworkAddressChangedEventHandler? NetworkAddressChanged diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs index 1cec0c010bca68..ff2ef61d397733 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs @@ -44,6 +44,7 @@ private static Socket? Socket private static Timer? s_availabilityTimer; private static bool s_availabilityHasChanged; + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static event NetworkAddressChangedEventHandler? NetworkAddressChanged diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs index bc0df09d18ac7c..e9b37f1eebfdae 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs @@ -16,6 +16,7 @@ public NetworkChange() { } + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static event NetworkAddressChangedEventHandler? NetworkAddressChanged diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs index 2b8ea339f92ddb..879faeb3e33041 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs @@ -28,6 +28,7 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC } } + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static event NetworkAddressChangedEventHandler? NetworkAddressChanged diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs new file mode 100644 index 00000000000000..3cd6963c692e0b --- /dev/null +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices.JavaScript; + +namespace System.Net.NetworkInformation +{ + internal static partial class BrowserNetworkInterfaceInterop + { + [JSImport("INTERNAL.network_wasm_online")] + public static partial bool IsOnline(); + } + + internal static class NetworkInterfacePal + { + public static NetworkInterface[] GetAllNetworkInterfaces() => throw new PlatformNotSupportedException(); + public static int IPv6LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); + public static int LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); + + public static bool GetIsNetworkAvailable() + { + return BrowserNetworkInterfaceInterop.IsOnline(); + } + } +} diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj index 345e1f518da3b4..65bf5104c8e750 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj @@ -3,7 +3,6 @@ true ../../src/Resources/Strings.resx $(NetCoreAppCurrent) - true $(DefineConstants);NETWORKINFORMATION_TEST diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts index 34646ca213bb97..54e80742d18840 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/exports.ts @@ -72,6 +72,7 @@ import { mono_wasm_bind_cs_function, mono_wasm_get_assembly_exports } from "./in import { mono_wasm_marshal_promise } from "./marshal-to-js"; import { ws_wasm_abort, ws_wasm_close, ws_wasm_create, ws_wasm_open, ws_wasm_receive, ws_wasm_send } from "./web-socket"; import { http_wasm_abort_request, http_wasm_abort_response, http_wasm_create_abort_controler, http_wasm_fetch, http_wasm_fetch_bytes, http_wasm_get_response_bytes, http_wasm_get_response_header_names, http_wasm_get_response_header_values, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes, http_wasm_supports_streaming_response } from "./http"; +import { network_wasm_online } from "./network-information"; import { diagnostics } from "./diagnostics"; import { mono_wasm_cancel_promise } from "./cancelable-promise"; import { @@ -485,6 +486,9 @@ const INTERNAL: any = { http_wasm_get_response_bytes, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes, + + // NetworkInformation + network_wasm_online }; // this represents visibility in the javascript diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts new file mode 100644 index 00000000000000..72b605931d284d --- /dev/null +++ b/src/mono/wasm/runtime/network-information.ts @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +export function network_wasm_online(): boolean { + return globalThis.navigator && globalThis.navigator.onLine; +} \ No newline at end of file From 3fbd1d734e8a1fed6254bfe4ac96b8ec7f86e72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 11 Jul 2022 15:20:52 +0200 Subject: [PATCH 02/17] Support NetworkChange.NetworkAvailabilityChanged on browser. --- .../NetworkAddressChange.Browser.cs | 21 +++++++++++++++++-- .../NetworkInterfacePal.Browser.cs | 3 +++ src/mono/wasm/runtime/exports.ts | 5 +++-- src/mono/wasm/runtime/network-information.ts | 7 ++++++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs index 34c774794387b9..8a1104b9cb0fc3 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -13,12 +13,29 @@ namespace System.Net.NetworkInformation { public partial class NetworkChange { + private static event NetworkAvailabilityChangedEventHandler? s_networkAvailabilityChanged; + [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged { - add => throw new PlatformNotSupportedException(); - remove => throw new PlatformNotSupportedException(); + add + { + if (s_networkAvailabilityChanged == null) + BrowserNetworkInterfaceInterop.AddChangeListener(OnNetworkChanged); + + s_networkAvailabilityChanged += value; + } + remove + { + s_networkAvailabilityChanged -= value; + } + } + + private static void OnNetworkChanged(bool isOnline) + { + if (s_networkAvailabilityChanged != null) + s_networkAvailabilityChanged?.Invoke(null, new NetworkAvailabilityEventArgs(isOnline)); } [UnsupportedOSPlatform("browser")] diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs index 3cd6963c692e0b..6a8e51b93567e0 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs @@ -9,6 +9,9 @@ internal static partial class BrowserNetworkInterfaceInterop { [JSImport("INTERNAL.network_wasm_online")] public static partial bool IsOnline(); + + [JSImport("INTERNAL.network_wasm_add_change_listener")] + public static partial void AddChangeListener([JSMarshalAs>] Action handler); } internal static class NetworkInterfacePal diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts index 54e80742d18840..109b6a0c79d99e 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/exports.ts @@ -72,7 +72,7 @@ import { mono_wasm_bind_cs_function, mono_wasm_get_assembly_exports } from "./in import { mono_wasm_marshal_promise } from "./marshal-to-js"; import { ws_wasm_abort, ws_wasm_close, ws_wasm_create, ws_wasm_open, ws_wasm_receive, ws_wasm_send } from "./web-socket"; import { http_wasm_abort_request, http_wasm_abort_response, http_wasm_create_abort_controler, http_wasm_fetch, http_wasm_fetch_bytes, http_wasm_get_response_bytes, http_wasm_get_response_header_names, http_wasm_get_response_header_values, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes, http_wasm_supports_streaming_response } from "./http"; -import { network_wasm_online } from "./network-information"; +import { network_wasm_online, network_wasm_add_change_listener } from "./network-information"; import { diagnostics } from "./diagnostics"; import { mono_wasm_cancel_promise } from "./cancelable-promise"; import { @@ -488,7 +488,8 @@ const INTERNAL: any = { http_wasm_get_streamed_response_bytes, // NetworkInformation - network_wasm_online + network_wasm_online, + network_wasm_add_change_listener }; // this represents visibility in the javascript diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts index 72b605931d284d..2dbdc046da5bd9 100644 --- a/src/mono/wasm/runtime/network-information.ts +++ b/src/mono/wasm/runtime/network-information.ts @@ -3,4 +3,9 @@ export function network_wasm_online(): boolean { return globalThis.navigator && globalThis.navigator.onLine; -} \ No newline at end of file +} + +export function network_wasm_add_change_listener(listener: (onLine: boolean) => void): void { + window.addEventListener("offline", () => listener(network_wasm_online())); + window.addEventListener("online", () => listener(network_wasm_online())); +} From 67bb6de731477e124285fbb5ec1beb3085e527c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 11 Jul 2022 15:30:00 +0200 Subject: [PATCH 03/17] Enable tests. --- .../tests/FunctionalTests/AddressParsingTests.cs | 1 + .../tests/FunctionalTests/AssemblyInfo.cs | 6 ------ .../tests/FunctionalTests/ConnectionsParsingTests.cs | 1 + .../tests/FunctionalTests/DnsParsingTests.cs | 1 + .../tests/FunctionalTests/IPGlobalPropertiesTest.cs | 1 + .../tests/FunctionalTests/LoggingTest.cs | 1 + .../tests/FunctionalTests/NetworkAddressChangedTests.cs | 1 + .../FunctionalTests/NetworkAvailabilityChangedTests.cs | 1 + .../tests/FunctionalTests/NetworkInterfaceBasicTest.cs | 6 ++++++ .../tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs | 1 + .../tests/FunctionalTests/PhysicalAddressTest.cs | 1 + .../tests/FunctionalTests/StatisticsParsingTests.cs | 1 + .../System.Net.NetworkInformation.Functional.Tests.csproj | 1 - 13 files changed, 16 insertions(+), 7 deletions(-) delete mode 100644 src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AssemblyInfo.cs diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs index 637cb202fe4362..7b01262ade44a2 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs @@ -7,6 +7,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class AddressParsingTests : FileCleanupTestBase { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AssemblyInfo.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AssemblyInfo.cs deleted file mode 100644 index 94698a9536f2f9..00000000000000 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Xunit; - -[assembly: SkipOnPlatform(TestPlatforms.Browser, "System.Net.NetworkInformation is not supported on Browser")] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs index 9f50bf682a9bca..911d6cd5c8440a 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class ConnectionsParsingTests : FileCleanupTestBase { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs index 92d70b6d81a658..366a060c79dd18 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs @@ -7,6 +7,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class DnsParsingTests : FileCleanupTestBase { [InlineData("NetworkFiles/resolv.conf")] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs index b1be503ee4cabf..e74a2c77f8c413 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs @@ -12,6 +12,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class IPGlobalPropertiesTest { private readonly ITestOutputHelper _log; diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs index b2c131f76f14b8..8c7dcb2569514d 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class LoggingTest { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs index 6a2a07a81fa0a8..d4051b252c614d 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs @@ -7,6 +7,7 @@ namespace System.Net.NetworkInformation.Tests { // Partial class used for both NetworkAddressChanged and NetworkAvailabilityChanged // so that the tests for each don't run concurrently + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public partial class NetworkChangedTests { private readonly NetworkAddressChangedEventHandler _addressHandler = delegate { }; diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs index 35a19be0b6da0e..70f441ed6af90a 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs @@ -7,6 +7,7 @@ namespace System.Net.NetworkInformation.Tests { // Partial class used for both NetworkAddressChanged and NetworkAvailabilityChanged // so that the tests for each don't run concurrently + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public partial class NetworkChangedTests { private readonly NetworkAvailabilityChangedEventHandler _availabilityHandler = delegate { }; diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs index 4b4a4ad44d9b23..2fbfff8f0f0741 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs @@ -20,6 +20,7 @@ public NetworkInterfaceBasicTest(ITestOutputHelper output) } [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void BasicTest_GetNetworkInterfaces_AtLeastOne() { Assert.NotEqual(0, NetworkInterface.GetAllNetworkInterfaces().Length); @@ -131,6 +132,7 @@ public void BasicTest_AccessInstanceProperties_NoExceptions_Bsd() [Fact] [Trait("IPv4", "true")] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void BasicTest_StaticLoopbackIndex_MatchesLoopbackNetworkInterface() { Assert.True(Capability.IPv4Support()); @@ -154,6 +156,7 @@ public void BasicTest_StaticLoopbackIndex_MatchesLoopbackNetworkInterface() [Fact] [Trait("IPv4", "true")] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void BasicTest_StaticLoopbackIndex_ExceptionIfV4NotSupported() { Assert.True(Capability.IPv4Support()); @@ -163,6 +166,7 @@ public void BasicTest_StaticLoopbackIndex_ExceptionIfV4NotSupported() [Trait("IPv6", "true")] [ConditionalFact(typeof(Socket), nameof(Socket.OSSupportsIPv6))] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void BasicTest_StaticIPv6LoopbackIndex_MatchesLoopbackNetworkInterface() { Assert.True(Capability.IPv6Support()); @@ -187,6 +191,7 @@ public void BasicTest_StaticIPv6LoopbackIndex_MatchesLoopbackNetworkInterface() [Trait("IPv6", "true")] [ConditionalFact(typeof(Socket), nameof(Socket.OSSupportsIPv6))] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void BasicTest_StaticIPv6LoopbackIndex_ExceptionIfV6NotSupported() { Assert.True(Capability.IPv6Support()); @@ -277,6 +282,7 @@ public void BasicTest_GetIsNetworkAvailable_Success() [ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] [SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD, "Expected behavior is different on OSX or FreeBSD")] [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Not supported on Browser, iOS, MacCatalyst, or tvOS.")] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] [InlineData(false)] [InlineData(true)] public async Task NetworkInterface_LoopbackInterfaceIndex_MatchesReceivedPackets(bool ipv6) diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs index 43a8e20df7cad9..47c242571daa41 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs @@ -10,6 +10,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class NetworkInterfaceIPv4Statistics { private readonly ITestOutputHelper _log; diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs index 2afabe0f86cde6..b0a17f63aae535 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class PhysicalAddressTest { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs index 6187644093f9e1..4cbc092e679ec7 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation.Tests { + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class StatisticsParsingTests : FileCleanupTestBase { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj index 65bf5104c8e750..73ae96b77e05ac 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj @@ -6,7 +6,6 @@ $(DefineConstants);NETWORKINFORMATION_TEST - From 491991846124f985bb1a65a2876c427caddd1be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 12 Jul 2022 09:19:18 +0200 Subject: [PATCH 04/17] Ensure change listener is attached only once. --- .../src/System.Net.NetworkInformation.csproj | 2 +- .../NetworkAddressChange.Browser.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj index a5fe8d4c87cd28..ec8dcc26bd624f 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj +++ b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj @@ -159,7 +159,7 @@ - + diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs index 8a1104b9cb0fc3..43a1c88c1615a8 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -13,6 +13,7 @@ namespace System.Net.NetworkInformation { public partial class NetworkChange { + private static bool s_isBrowserNetworkChangeListenerAttached; private static event NetworkAvailabilityChangedEventHandler? s_networkAvailabilityChanged; [UnsupportedOSPlatform("illumos")] @@ -21,8 +22,11 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC { add { - if (s_networkAvailabilityChanged == null) + if (!s_isBrowserNetworkChangeListenerAttached) + { BrowserNetworkInterfaceInterop.AddChangeListener(OnNetworkChanged); + s_isBrowserNetworkChangeListenerAttached = true; + } s_networkAvailabilityChanged += value; } @@ -32,11 +36,7 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC } } - private static void OnNetworkChanged(bool isOnline) - { - if (s_networkAvailabilityChanged != null) - s_networkAvailabilityChanged?.Invoke(null, new NetworkAvailabilityEventArgs(isOnline)); - } + private static void OnNetworkChanged(bool isOnline) => s_networkAvailabilityChanged?.Invoke(null, new NetworkAvailabilityEventArgs(isOnline)); [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] From 2b8856e2012fd4606053d07e9fe77f88cb9f5595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 12 Jul 2022 10:12:58 +0200 Subject: [PATCH 05/17] Skip test for NetworkInterface.GetIsNetworkAvailable on NodeJS and V8. --- .../tests/FunctionalTests/NetworkInterfaceBasicTest.cs | 2 +- src/mono/wasm/runtime/network-information.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs index 2fbfff8f0f0741..92a980d8d441b1 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs @@ -272,7 +272,7 @@ public void BasicTest_GetIPInterfaceStatistics_Success_Bsd() } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupported))] public void BasicTest_GetIsNetworkAvailable_Success() { Assert.True(NetworkInterface.GetIsNetworkAvailable()); diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts index 2dbdc046da5bd9..c0245468c4fb69 100644 --- a/src/mono/wasm/runtime/network-information.ts +++ b/src/mono/wasm/runtime/network-information.ts @@ -6,6 +6,8 @@ export function network_wasm_online(): boolean { } export function network_wasm_add_change_listener(listener: (onLine: boolean) => void): void { - window.addEventListener("offline", () => listener(network_wasm_online())); - window.addEventListener("online", () => listener(network_wasm_online())); + if (window) { + window.addEventListener("offline", () => listener(network_wasm_online())); + window.addEventListener("online", () => listener(network_wasm_online())); + } } From d314fca0a964331803fb34199998cb069d1e006e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 12 Jul 2022 11:11:34 +0200 Subject: [PATCH 06/17] PSNE with error message. --- .../Net/NetworkInformation/NetworkAddressChange.Browser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs index 43a1c88c1615a8..58a21fc898ba8a 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -43,8 +43,8 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC [UnsupportedOSPlatform("solaris")] public static event NetworkAddressChangedEventHandler? NetworkAddressChanged { - add => throw new PlatformNotSupportedException(); - remove => throw new PlatformNotSupportedException(); + add => throw new System.PlatformNotSupportedException(System.SR.SystemNetNetworkInformation_PlatformNotSupported); + remove => throw new System.PlatformNotSupportedException(System.SR.SystemNetNetworkInformation_PlatformNotSupported); } [EditorBrowsableAttribute(EditorBrowsableState.Never)] From 7eb6f8dbfa475ed6fffe329c6f5d61183ba9977c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 12 Jul 2022 11:39:25 +0200 Subject: [PATCH 07/17] UnsupportedOSPlatform for everything not supported on browser. --- .../ref/System.Net.NetworkInformation.cs | 46 +++++++++++++++++++ .../src/System.Net.NetworkInformation.csproj | 6 +-- .../DuplicateAddressDetectionState.cs | 1 + .../GatewayIPAddressInformation.cs | 1 + .../GatewayIPAddressInformationCollection.cs | 1 + .../IPAddressInformation.cs | 1 + .../IPAddressInformationCollection.cs | 1 + .../NetworkInformation/IPGlobalProperties.cs | 1 + .../NetworkInformation/IPGlobalStatistics.cs | 1 + .../IPInterfaceProperties.cs | 1 + .../IPInterfaceStatistics.cs | 1 + .../IPv4InterfaceProperties.cs | 1 + .../IPv6InterfaceProperties.cs | 1 + .../NetworkInformation/IcmpV4Statistics.cs | 1 + .../NetworkInformation/IcmpV6Statistics.cs | 1 + .../Ipv4InterfaceStatistics.cs | 1 + .../MulticastIPAddressInformation.cs | 1 + ...MulticastIPAddressInformationCollection.cs | 1 + .../Net/NetworkInformation/NetBiosNodeType.cs | 1 + .../NetworkInformation/NetworkInterface.cs | 16 +++++++ .../NetworkInterfaceComponent.cs | 1 + .../NetworkInterfaceType.cs | 1 + .../NetworkInformation/OperationalStatus.cs | 1 + .../Net/NetworkInformation/PhysicalAddress.cs | 1 + .../Net/NetworkInformation/PrefixOrigin.cs | 1 + .../Net/NetworkInformation/ScopeLevel.cs | 1 + .../Net/NetworkInformation/SuffixOrigin.cs | 1 + .../Net/NetworkInformation/TcpConnection.cs | 1 + .../System/Net/NetworkInformation/TcpState.cs | 1 + .../Net/NetworkInformation/TcpStatistics.cs | 1 + .../Net/NetworkInformation/UdpStatistics.cs | 1 + .../UnicastIPAddressInformation.cs | 1 + .../UnicastIPAddressInformationCollection.cs | 1 + 33 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs index 3bdf55cd8e8769..7ab2067fc04716 100644 --- a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum DuplicateAddressDetectionState { Invalid = 0, @@ -14,11 +15,13 @@ public enum DuplicateAddressDetectionState Deprecated = 3, Preferred = 4, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class GatewayIPAddressInformation { protected GatewayIPAddressInformation() { } public abstract System.Net.IPAddress Address { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class GatewayIPAddressInformationCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { protected internal GatewayIPAddressInformationCollection() { } @@ -33,6 +36,7 @@ public virtual void CopyTo(System.Net.NetworkInformation.GatewayIPAddressInforma public virtual bool Remove(System.Net.NetworkInformation.GatewayIPAddressInformation address) { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IcmpV4Statistics { protected IcmpV4Statistics() { } @@ -63,6 +67,7 @@ protected IcmpV4Statistics() { } public abstract long TimestampRequestsReceived { get; } public abstract long TimestampRequestsSent { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IcmpV6Statistics { protected IcmpV6Statistics() { } @@ -99,6 +104,7 @@ protected IcmpV6Statistics() { } public abstract long TimeExceededMessagesReceived { get; } public abstract long TimeExceededMessagesSent { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPAddressInformation { protected IPAddressInformation() { } @@ -106,6 +112,7 @@ protected IPAddressInformation() { } public abstract bool IsDnsEligible { get; } public abstract bool IsTransient { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class IPAddressInformationCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { internal IPAddressInformationCollection() { } @@ -120,6 +127,7 @@ public virtual void CopyTo(System.Net.NetworkInformation.IPAddressInformation[] public virtual bool Remove(System.Net.NetworkInformation.IPAddressInformation address) { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPGlobalProperties { protected IPGlobalProperties() { } @@ -158,6 +166,7 @@ protected IPGlobalProperties() { } public virtual System.Net.NetworkInformation.UnicastIPAddressInformationCollection GetUnicastAddresses() { throw null; } public virtual System.Threading.Tasks.Task GetUnicastAddressesAsync() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPGlobalStatistics { protected IPGlobalStatistics() { } @@ -204,6 +213,7 @@ protected IPGlobalStatistics() { } [System.Runtime.Versioning.UnsupportedOSPlatform("android")] public abstract long ReceivedPacketsWithUnknownProtocol { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPInterfaceProperties { protected IPInterfaceProperties() { } @@ -228,6 +238,7 @@ protected IPInterfaceProperties() { } public abstract System.Net.NetworkInformation.IPv4InterfaceProperties GetIPv4Properties(); public abstract System.Net.NetworkInformation.IPv6InterfaceProperties GetIPv6Properties(); } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPInterfaceStatistics { protected IPInterfaceStatistics() { } @@ -248,6 +259,7 @@ protected IPInterfaceStatistics() { } public abstract long UnicastPacketsReceived { get; } public abstract long UnicastPacketsSent { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPv4InterfaceProperties { protected IPv4InterfaceProperties() { } @@ -264,6 +276,7 @@ protected IPv4InterfaceProperties() { } [System.Runtime.Versioning.UnsupportedOSPlatform("android")] public abstract bool UsesWins { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPv4InterfaceStatistics { protected IPv4InterfaceStatistics() { } @@ -284,6 +297,7 @@ protected IPv4InterfaceStatistics() { } public abstract long UnicastPacketsReceived { get; } public abstract long UnicastPacketsSent { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPv6InterfaceProperties { protected IPv6InterfaceProperties() { } @@ -291,6 +305,7 @@ protected IPv6InterfaceProperties() { } public abstract int Mtu { get; } public virtual long GetScopeId(System.Net.NetworkInformation.ScopeLevel scopeLevel) { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class MulticastIPAddressInformation : System.Net.NetworkInformation.IPAddressInformation { protected MulticastIPAddressInformation() { } @@ -301,6 +316,7 @@ protected MulticastIPAddressInformation() { } public abstract System.Net.NetworkInformation.PrefixOrigin PrefixOrigin { get; } public abstract System.Net.NetworkInformation.SuffixOrigin SuffixOrigin { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class MulticastIPAddressInformationCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { protected internal MulticastIPAddressInformationCollection() { } @@ -315,6 +331,7 @@ public virtual void CopyTo(System.Net.NetworkInformation.MulticastIPAddressInfor public virtual bool Remove(System.Net.NetworkInformation.MulticastIPAddressInformation address) { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum NetBiosNodeType { Unknown = 0, @@ -356,39 +373,57 @@ protected NetworkInformationException(System.Runtime.Serialization.Serialization public abstract partial class NetworkInterface { protected NetworkInterface() { } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual string Description { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual string Id { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("illumos")] [System.Runtime.Versioning.UnsupportedOSPlatform("solaris")] public static int IPv6LoopbackInterfaceIndex { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual bool IsReceiveOnly { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("illumos")] [System.Runtime.Versioning.UnsupportedOSPlatform("solaris")] public static int LoopbackInterfaceIndex { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual string Name { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual System.Net.NetworkInformation.NetworkInterfaceType NetworkInterfaceType { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual System.Net.NetworkInformation.OperationalStatus OperationalStatus { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual long Speed { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual bool SupportsMulticast { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("illumos")] [System.Runtime.Versioning.UnsupportedOSPlatform("solaris")] public static System.Net.NetworkInformation.NetworkInterface[] GetAllNetworkInterfaces() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("android")] public virtual System.Net.NetworkInformation.IPInterfaceStatistics GetIPStatistics() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("android")] public virtual System.Net.NetworkInformation.IPv4InterfaceStatistics GetIPv4Statistics() { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatform("illumos")] [System.Runtime.Versioning.UnsupportedOSPlatform("solaris")] public static bool GetIsNetworkAvailable() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public virtual bool Supports(System.Net.NetworkInformation.NetworkInterfaceComponent networkInterfaceComponent) { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum NetworkInterfaceComponent { IPv4 = 0, IPv6 = 1, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum NetworkInterfaceType { Unknown = 1, @@ -420,6 +455,7 @@ public enum NetworkInterfaceType Wwanpp = 243, Wwanpp2 = 244, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum OperationalStatus { Up = 1, @@ -430,6 +466,7 @@ public enum OperationalStatus NotPresent = 6, LowerLayerDown = 7, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class PhysicalAddress { public static readonly System.Net.NetworkInformation.PhysicalAddress None; @@ -443,6 +480,7 @@ public PhysicalAddress(byte[] address) { } public static bool TryParse(ReadOnlySpan address, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Net.NetworkInformation.PhysicalAddress? value) { throw null; } public override string ToString() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum PrefixOrigin { Other = 0, @@ -451,6 +489,7 @@ public enum PrefixOrigin Dhcp = 3, RouterAdvertisement = 4, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum ScopeLevel { None = 0, @@ -462,6 +501,7 @@ public enum ScopeLevel Organization = 8, Global = 14, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum SuffixOrigin { Other = 0, @@ -471,6 +511,7 @@ public enum SuffixOrigin LinkLayerAddress = 4, Random = 5, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class TcpConnectionInformation { protected TcpConnectionInformation() { } @@ -478,6 +519,7 @@ protected TcpConnectionInformation() { } public abstract System.Net.IPEndPoint RemoteEndPoint { get; } public abstract System.Net.NetworkInformation.TcpState State { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum TcpState { Unknown = 0, @@ -494,6 +536,7 @@ public enum TcpState TimeWait = 11, DeleteTcb = 12, } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class TcpStatistics { protected TcpStatistics() { } @@ -512,6 +555,7 @@ protected TcpStatistics() { } public abstract long SegmentsResent { get; } public abstract long SegmentsSent { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class UdpStatistics { protected UdpStatistics() { } @@ -521,6 +565,7 @@ protected UdpStatistics() { } public abstract long IncomingDatagramsWithErrors { get; } public abstract int UdpListeners { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class UnicastIPAddressInformation : System.Net.NetworkInformation.IPAddressInformation { protected UnicastIPAddressInformation() { } @@ -533,6 +578,7 @@ protected UnicastIPAddressInformation() { } public abstract System.Net.NetworkInformation.PrefixOrigin PrefixOrigin { get; } public abstract System.Net.NetworkInformation.SuffixOrigin SuffixOrigin { get; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class UnicastIPAddressInformationCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { protected internal UnicastIPAddressInformationCollection() { } diff --git a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj index ec8dcc26bd624f..e9515494409988 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj +++ b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj @@ -1,4 +1,4 @@ - + true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent) @@ -48,7 +48,7 @@ - + @@ -98,7 +98,7 @@ - + diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/DuplicateAddressDetectionState.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/DuplicateAddressDetectionState.cs index d51caca2086819..f8e3da168cd05e 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/DuplicateAddressDetectionState.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/DuplicateAddressDetectionState.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Specifies the current state of an IP address. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum DuplicateAddressDetectionState { Invalid = 0, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformation.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformation.cs index dfd9113f634fad..2e156d11e8bfa5 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformation.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides information about a network interface address. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class GatewayIPAddressInformation { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformationCollection.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformationCollection.cs index 049419360c2f37..46ae5cd0e9340a 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformationCollection.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/GatewayIPAddressInformationCollection.cs @@ -5,6 +5,7 @@ namespace System.Net.NetworkInformation { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public class GatewayIPAddressInformationCollection : ICollection { private readonly List _addresses; diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformation.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformation.cs index 9369864d1315ba..d348b1b7074a7e 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformation.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides information about a network interface address. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IPAddressInformation { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformationCollection.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformationCollection.cs index e0672467f09f33..c3105491710d26 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformationCollection.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressInformationCollection.cs @@ -5,6 +5,7 @@ namespace System.Net.NetworkInformation { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public class IPAddressInformationCollection : ICollection { private readonly List _addresses = new List(); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs index 1371a47d3ed945..8778a38ecffec8 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs @@ -10,6 +10,7 @@ namespace System.Net.NetworkInformation /// Provides various global machine properties related to Internet Protocol (IP), /// such as the local host name, domain name, and active socket connections. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IPGlobalProperties { [UnsupportedOSPlatform("illumos")] diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalStatistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalStatistics.cs index 04b9f14f1eab2b..17f44d9d2baafa 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalStatistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalStatistics.cs @@ -8,6 +8,7 @@ namespace System.Net.NetworkInformation /// /// Provides Internet Protocol (IP) statistical data for the local machine. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IPGlobalStatistics { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs index 863737ce18f6d3..7a2aa6741d015e 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs @@ -9,6 +9,7 @@ namespace System.Net.NetworkInformation /// Provides information about a network interface that supports Internet Protocol (IP). /// such as the addresses assigned to the adapter, and other DNS and routing-related information. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IPInterfaceProperties { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceStatistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceStatistics.cs index 4570a7b757ce29..02c97d5b9cf117 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceStatistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceStatistics.cs @@ -9,6 +9,7 @@ namespace System.Net.NetworkInformation /// Provides statistics information for a particular network interface, /// such as the total number of bytes sent and received. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IPInterfaceStatistics { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv4InterfaceProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv4InterfaceProperties.cs index 9f9d0b1e3766dd..732dfac81a591f 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv4InterfaceProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv4InterfaceProperties.cs @@ -8,6 +8,7 @@ namespace System.Net.NetworkInformation /// /// Provides information about network interfaces that support Internet Protocol (IP) version 4.0. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IPv4InterfaceProperties { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv6InterfaceProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv6InterfaceProperties.cs index 534ac51e853409..2625aa8cb2926d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv6InterfaceProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPv6InterfaceProperties.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides information about network interfaces that support Internet Protocol (IP) version 6.0. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IPv6InterfaceProperties { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV4Statistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV4Statistics.cs index 2d677ef9fb5fe7..85d0a710c460e0 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV4Statistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV4Statistics.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides Internet Control Message Protocol for IPv4 (ICMPv4) statistical data for the local computer. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IcmpV4Statistics { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV6Statistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV6Statistics.cs index 6f9d3e76b3dc5e..3981f0f2ff7667 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV6Statistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IcmpV6Statistics.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides Internet Control Message Protocol for Internet Protocol version 6 (ICMPv6) statistical data for the local computer. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class IcmpV6Statistics { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/Ipv4InterfaceStatistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/Ipv4InterfaceStatistics.cs index 553486796717ff..ffe5fa40af71ee 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/Ipv4InterfaceStatistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/Ipv4InterfaceStatistics.cs @@ -8,6 +8,7 @@ namespace System.Net.NetworkInformation /// /// Provides statistical data for a network interface on the local computer. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class IPv4InterfaceStatistics { protected IPv4InterfaceStatistics() { } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformation.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformation.cs index 9dfe8b5bfb0526..7dbc4a1597ea33 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformation.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides information about a network interface's unicast address. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class MulticastIPAddressInformation : IPAddressInformation { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformationCollection.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformationCollection.cs index 255d2df4b7fe16..a139a9d5d6e939 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformationCollection.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/MulticastIPAddressInformationCollection.cs @@ -5,6 +5,7 @@ namespace System.Net.NetworkInformation { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public class MulticastIPAddressInformationCollection : ICollection { private readonly List _addresses = new List(); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetBiosNodeType.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetBiosNodeType.cs index 0a27a770a02fd4..68701213e97201 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetBiosNodeType.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetBiosNodeType.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Specifies the Network Basic Input/Output System (NetBIOS) node type. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum NetBiosNodeType { Unknown = 0, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterface.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterface.cs index 24f02186c3dc3a..a67b9326f99ddb 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterface.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterface.cs @@ -11,6 +11,7 @@ public abstract class NetworkInterface /// Returns objects that describe the network interfaces on the local computer. /// /// An array of all network interfaces on the local computer. + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static NetworkInterface[] GetAllNetworkInterfaces() @@ -25,6 +26,7 @@ public static bool GetIsNetworkAvailable() return NetworkInterfacePal.GetIsNetworkAvailable(); } + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static int IPv6LoopbackInterfaceIndex @@ -35,6 +37,7 @@ public static int IPv6LoopbackInterfaceIndex } } + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] [UnsupportedOSPlatform("solaris")] public static int LoopbackInterfaceIndex @@ -45,22 +48,26 @@ public static int LoopbackInterfaceIndex } } + [UnsupportedOSPlatform("browser")] public virtual string Id { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } /// /// Gets the name of the network interface. /// + [UnsupportedOSPlatform("browser")] public virtual string Name { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } /// /// Gets the description of the network interface /// + [UnsupportedOSPlatform("browser")] public virtual string Description { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } /// /// Gets the IP properties for this network interface. /// /// The interface's IP properties. + [UnsupportedOSPlatform("browser")] public virtual IPInterfaceProperties GetIPProperties() { throw NotImplemented.ByDesignWithMessage(SR.net_MethodNotImplementedException); @@ -70,6 +77,7 @@ public virtual IPInterfaceProperties GetIPProperties() /// Provides Internet Protocol (IP) statistical data for this network interface. /// /// The interface's IP statistics. + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("android")] public virtual IPInterfaceStatistics GetIPStatistics() { @@ -82,6 +90,7 @@ public virtual IPInterfaceStatistics GetIPStatistics() /// Do not use this method, use GetIPStatistics instead. /// /// The interface's IP statistics. + [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("android")] public virtual IPv4InterfaceStatistics GetIPv4Statistics() { @@ -91,27 +100,32 @@ public virtual IPv4InterfaceStatistics GetIPv4Statistics() /// /// Gets the current operational state of the network connection. /// + [UnsupportedOSPlatform("browser")] public virtual OperationalStatus OperationalStatus { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } /// /// Gets the speed of the interface in bits per second as reported by the interface. /// + [UnsupportedOSPlatform("browser")] public virtual long Speed { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } /// /// Gets a bool value that indicates whether the network interface is set to only receive data packets. /// + [UnsupportedOSPlatform("browser")] public virtual bool IsReceiveOnly { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } /// /// Gets a bool value that indicates whether this network interface is enabled to receive multicast packets. /// + [UnsupportedOSPlatform("browser")] public virtual bool SupportsMulticast { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } /// /// Gets the physical address of this network interface /// /// The interface's physical address. + [UnsupportedOSPlatform("browser")] public virtual PhysicalAddress GetPhysicalAddress() { throw NotImplemented.ByDesignWithMessage(SR.net_MethodNotImplementedException); @@ -120,8 +134,10 @@ public virtual PhysicalAddress GetPhysicalAddress() /// /// Gets the interface type. /// + [UnsupportedOSPlatform("browser")] public virtual NetworkInterfaceType NetworkInterfaceType { get { throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException); } } + [UnsupportedOSPlatform("browser")] public virtual bool Supports(NetworkInterfaceComponent networkInterfaceComponent) { throw NotImplemented.ByDesignWithMessage(SR.net_MethodNotImplementedException); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceComponent.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceComponent.cs index 4a531878b3bdd6..e60c7b41dc3164 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceComponent.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceComponent.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Specified the list of Networking components that are supported on a Network Interface /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum NetworkInterfaceComponent { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceType.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceType.cs index b624bba2b83048..290d10d6b19d3b 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceType.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfaceType.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Specifies types of network interfaces. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum NetworkInterfaceType { Unknown = 1, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/OperationalStatus.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/OperationalStatus.cs index 2c67a43578d44f..ab3e8b616cd3b5 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/OperationalStatus.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/OperationalStatus.cs @@ -3,6 +3,7 @@ namespace System.Net.NetworkInformation { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum OperationalStatus { Up = 1, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs index e745a55f83f824..a00ce5bcdb1ac3 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public class PhysicalAddress { private readonly byte[] _address; diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PrefixOrigin.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PrefixOrigin.cs index 12275ea8f07a26..b57cb1dc8db45d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PrefixOrigin.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PrefixOrigin.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Specifies how an IP address network prefix was located. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum PrefixOrigin { Other = 0, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/ScopeLevel.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/ScopeLevel.cs index 7b4977b83f48e8..9c8cb0b1f50610 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/ScopeLevel.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/ScopeLevel.cs @@ -4,6 +4,7 @@ namespace System.Net.NetworkInformation { // See SCOPE_LEVEL + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum ScopeLevel { None = 0, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SuffixOrigin.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SuffixOrigin.cs index ff314fe16b7755..99356fd1a3c921 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SuffixOrigin.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SuffixOrigin.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Specifies how an IP address host suffix was located. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum SuffixOrigin { Other = 0, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpConnection.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpConnection.cs index 5667d7f8ce118f..23ef3bbe49c657 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpConnection.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpConnection.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides information about the Transmission Control Protocol (TCP) connections on the local computer. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class TcpConnectionInformation { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpState.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpState.cs index 94e25952b63315..11c6c99f7a72c9 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpState.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpState.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Specifies the states of a Transmission Control Protocol (TCP) connection. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public enum TcpState { Unknown, diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpStatistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpStatistics.cs index 1b9dd1a0817ca2..cad82d74e69860 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpStatistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TcpStatistics.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides Transmission Control Protocol (TCP) statistical data. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class TcpStatistics { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UdpStatistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UdpStatistics.cs index 90d8f4dfb20ffd..ec4c3d55977dd4 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UdpStatistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UdpStatistics.cs @@ -6,6 +6,7 @@ namespace System.Net.NetworkInformation /// /// Provides User Datagram Protocol (UDP) statistical data. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class UdpStatistics { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformation.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformation.cs index 3cd00d49706124..0266ff4ab23ac0 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformation.cs @@ -9,6 +9,7 @@ namespace System.Net.NetworkInformation /// /// Provides information about a network interface's unicast address. /// + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract class UnicastIPAddressInformation : IPAddressInformation { /// diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformationCollection.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformationCollection.cs index dcca0a443a0bd2..9b805f6c0ae841 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformationCollection.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnicastIPAddressInformationCollection.cs @@ -5,6 +5,7 @@ namespace System.Net.NetworkInformation { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public class UnicastIPAddressInformationCollection : ICollection { private readonly List _addresses = From 2baf83fd2a162f75850885733bf63c2fcbd97c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 12 Jul 2022 13:40:33 +0200 Subject: [PATCH 08/17] Update ApiCompatBaseline. --- .../apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt b/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt index 98c8b5af978c2d..943ffef825c23a 100644 --- a/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt +++ b/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt @@ -41,6 +41,7 @@ Compat issues with assembly netstandard: CannotChangeAttribute : Attribute 'System.Runtime.Versioning.SupportedOSPlatformAttribute' on 'System.Diagnostics.Process.MaxWorkingSet.set(System.IntPtr)' changed from '[SupportedOSPlatformAttribute("freebsd")]' in the contract to '[SupportedOSPlatformAttribute("freebsd")]' in the implementation. CannotChangeAttribute : Attribute 'System.Runtime.Versioning.SupportedOSPlatformAttribute' on 'System.Diagnostics.Process.MinWorkingSet.set(System.IntPtr)' changed from '[SupportedOSPlatformAttribute("freebsd")]' in the contract to '[SupportedOSPlatformAttribute("freebsd")]' in the implementation. CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.Http.HttpClientHandler.Proxy' changed from '[UnsupportedOSPlatformAttribute("browser")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation. +CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()' changed from '[UnsupportedOSPlatformAttribute("illumos")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAttribute' exists on 'System.Numerics.Vector.CopyTo(System.Span)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAttribute' exists on 'System.Numerics.Vector.CopyTo(System.Span)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAttribute' exists on 'System.Numerics.Vector.CopyTo(T[])' in the contract but not the implementation. @@ -103,6 +104,7 @@ CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatfo Compat issues with assembly System: CannotChangeAttribute : Attribute 'System.Runtime.Versioning.SupportedOSPlatformAttribute' on 'System.Diagnostics.Process.MaxWorkingSet.set(System.IntPtr)' changed from '[SupportedOSPlatformAttribute("freebsd")]' in the contract to '[SupportedOSPlatformAttribute("freebsd")]' in the implementation. CannotChangeAttribute : Attribute 'System.Runtime.Versioning.SupportedOSPlatformAttribute' on 'System.Diagnostics.Process.MinWorkingSet.set(System.IntPtr)' changed from '[SupportedOSPlatformAttribute("freebsd")]' in the contract to '[SupportedOSPlatformAttribute("freebsd")]' in the implementation. +CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()' changed from '[UnsupportedOSPlatformAttribute("illumos")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation. CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Security.Cryptography.X509Certificates.PublicKey.GetDSAPublicKey()' changed from '[UnsupportedOSPlatformAttribute("ios")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation. Compat issues with assembly System.Core: CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Aes' in the contract but not the implementation. @@ -119,8 +121,12 @@ CannotChangeAttribute : Attribute 'System.Runtime.Versioning.SupportedOSPlatform Compat issues with assembly System.IO.FileSystem: CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.IO.FileStream.Lock(System.Int64, System.Int64)' changed from '[UnsupportedOSPlatformAttribute("ios")]' in the contract to '[UnsupportedOSPlatformAttribute("freebsd")]' in the implementation. CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.IO.FileStream.Unlock(System.Int64, System.Int64)' changed from '[UnsupportedOSPlatformAttribute("ios")]' in the contract to '[UnsupportedOSPlatformAttribute("freebsd")]' in the implementation. +Compat issues with assembly System.Net: +CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()' changed from '[UnsupportedOSPlatformAttribute("illumos")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation. Compat issues with assembly System.Net.Http: CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.Http.HttpClientHandler.Proxy' changed from '[UnsupportedOSPlatformAttribute("browser")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation. +Compat issues with assembly System.Net.NetworkInformation: +CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()' changed from '[UnsupportedOSPlatformAttribute("illumos")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation. Compat issues with assembly System.Net.Security: CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Net.Security.SslCertificateTrust.CreateForX509Collection(System.Security.Cryptography.X509Certificates.X509Certificate2Collection, System.Boolean)' in the contract but not the implementation. Compat issues with assembly System.Numerics.Vectors: From 2ee970e14f0609c79bd7d5370245538f9855983b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 13 Jul 2022 10:01:12 +0200 Subject: [PATCH 09/17] Update src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs Co-authored-by: Ankit Jain --- .../Net/NetworkInformation/NetworkInterfacePal.Browser.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs index 6a8e51b93567e0..0e99888a0ff997 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs @@ -20,9 +20,6 @@ internal static class NetworkInterfacePal public static int IPv6LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); public static int LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); - public static bool GetIsNetworkAvailable() - { - return BrowserNetworkInterfaceInterop.IsOnline(); - } + public static bool GetIsNetworkAvailable() => BrowserNetworkInterfaceInterop.IsOnline(); } } From 1a1eca27e7a2d2ffbd51264f92d06fd57117bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 13 Jul 2022 10:34:55 +0200 Subject: [PATCH 10/17] Enable NetworkAvailabilityChanged tests that don't include NetworkAddressChanged. --- .../tests/FunctionalTests/NetworkAddressChangedTests.cs | 3 ++- .../FunctionalTests/NetworkAvailabilityChangedTests.cs | 8 +++++--- .../tests/FunctionalTests/NetworkInterfaceBasicTest.cs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs index d4051b252c614d..af5a1fe4269ca2 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs @@ -7,12 +7,12 @@ namespace System.Net.NetworkInformation.Tests { // Partial class used for both NetworkAddressChanged and NetworkAvailabilityChanged // so that the tests for each don't run concurrently - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public partial class NetworkChangedTests { private readonly NetworkAddressChangedEventHandler _addressHandler = delegate { }; [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void NetworkAddressChanged_AddRemove_Success() { NetworkChange.NetworkAddressChanged += _addressHandler; @@ -20,6 +20,7 @@ public void NetworkAddressChanged_AddRemove_Success() } [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void NetworkAddressChanged_JustRemove_Success() { NetworkChange.NetworkAddressChanged -= _addressHandler; diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs index 70f441ed6af90a..ea2cbdc361e204 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs @@ -7,25 +7,25 @@ namespace System.Net.NetworkInformation.Tests { // Partial class used for both NetworkAddressChanged and NetworkAvailabilityChanged // so that the tests for each don't run concurrently - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public partial class NetworkChangedTests { private readonly NetworkAvailabilityChangedEventHandler _availabilityHandler = delegate { }; - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] public void NetworkAvailabilityChanged_AddRemove_Success() { NetworkChange.NetworkAvailabilityChanged += _availabilityHandler; NetworkChange.NetworkAvailabilityChanged -= _availabilityHandler; } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] public void NetworkAvailabilityChanged_JustRemove_Success() { NetworkChange.NetworkAvailabilityChanged -= _availabilityHandler; } [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void NetworkAddressChanged_Add_DoesNotBlock() { // Register without unregistering. @@ -39,6 +39,7 @@ public void NetworkAddressChanged_Add_DoesNotBlock() } [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void NetworkAddressChanged_AddAndRemove_NetworkAvailabilityChanged_JustRemove_Success() { NetworkChange.NetworkAddressChanged += _addressHandler; @@ -51,6 +52,7 @@ public void NetworkAddressChanged_AddAndRemove_NetworkAvailabilityChanged_JustRe [InlineData(false, true)] [InlineData(true, false)] [InlineData(true, true)] + [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public void NetworkAvailabilityChanged_NetworkAddressChanged_AddAndRemove_Success(bool addAddressFirst, bool removeAddressFirst) { if (addAddressFirst) diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs index 92a980d8d441b1..d4c746e5b954f3 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs @@ -272,7 +272,7 @@ public void BasicTest_GetIPInterfaceStatistics_Success_Bsd() } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupported))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] public void BasicTest_GetIsNetworkAvailable_Success() { Assert.True(NetworkInterface.GetIsNetworkAvailable()); From 947d3254e124e8a5eb3368775dc1a00601decaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 13 Jul 2022 10:36:57 +0200 Subject: [PATCH 11/17] Rename OnNetworkChanged to OnNetworkAvailabilityChanged Co-authored-by: Ankit Jain --- .../Net/NetworkInformation/NetworkAddressChange.Browser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs index 58a21fc898ba8a..9941dc6d9d0f44 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -24,7 +24,7 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC { if (!s_isBrowserNetworkChangeListenerAttached) { - BrowserNetworkInterfaceInterop.AddChangeListener(OnNetworkChanged); + BrowserNetworkInterfaceInterop.AddChangeListener(OnNetworkAvailabilityChanged); s_isBrowserNetworkChangeListenerAttached = true; } @@ -36,7 +36,7 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC } } - private static void OnNetworkChanged(bool isOnline) => s_networkAvailabilityChanged?.Invoke(null, new NetworkAvailabilityEventArgs(isOnline)); + private static void OnNetworkAvailabilityChanged(bool isOnline) => s_networkAvailabilityChanged?.Invoke(null, new NetworkAvailabilityEventArgs(isOnline)); [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("illumos")] From 2afa020140d20ab607505bac0ff88fcf03ef696f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 13 Jul 2022 14:48:01 +0200 Subject: [PATCH 12/17] Unsubscribe browser events. --- .../src/System.Net.NetworkInformation.csproj | 1 + .../BrowserNetworkInterfaceInterop.cs | 19 ++++++++++++ .../NetworkAddressChange.Browser.cs | 11 ++++--- .../NetworkInterfacePal.Browser.cs | 11 ------- src/mono/wasm/runtime/exports.ts | 5 ++-- src/mono/wasm/runtime/network-information.ts | 29 +++++++++++++++++-- 6 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs diff --git a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj index e9515494409988..2febec989d7b0b 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj +++ b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj @@ -161,6 +161,7 @@ + diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs new file mode 100644 index 00000000000000..834400e42914ef --- /dev/null +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices.JavaScript; + +namespace System.Net.NetworkInformation +{ + internal static partial class BrowserNetworkInterfaceInterop + { + [JSImport("INTERNAL.network_wasm_online")] + public static partial bool IsOnline(); + + [JSImport("INTERNAL.network_wasm_set_change_listener")] + public static partial void SetChangeListener([JSMarshalAs>] Action handler); + + [JSImport("INTERNAL.network_wasm_remove_change_listener")] + public static partial void RemoveChangeListener(); + } +} diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs index 9941dc6d9d0f44..4dcef3de53ea95 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -13,7 +13,6 @@ namespace System.Net.NetworkInformation { public partial class NetworkChange { - private static bool s_isBrowserNetworkChangeListenerAttached; private static event NetworkAvailabilityChangedEventHandler? s_networkAvailabilityChanged; [UnsupportedOSPlatform("illumos")] @@ -22,17 +21,17 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC { add { - if (!s_isBrowserNetworkChangeListenerAttached) - { - BrowserNetworkInterfaceInterop.AddChangeListener(OnNetworkAvailabilityChanged); - s_isBrowserNetworkChangeListenerAttached = true; - } + if (s_networkAvailabilityChanged == null) + BrowserNetworkInterfaceInterop.SetChangeListener(OnNetworkAvailabilityChanged); s_networkAvailabilityChanged += value; } remove { s_networkAvailabilityChanged -= value; + + if (s_networkAvailabilityChanged == null) + BrowserNetworkInterfaceInterop.RemoveChangeListener(); } } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs index 0e99888a0ff997..6a37b682d021ce 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs @@ -1,19 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Runtime.InteropServices.JavaScript; - namespace System.Net.NetworkInformation { - internal static partial class BrowserNetworkInterfaceInterop - { - [JSImport("INTERNAL.network_wasm_online")] - public static partial bool IsOnline(); - - [JSImport("INTERNAL.network_wasm_add_change_listener")] - public static partial void AddChangeListener([JSMarshalAs>] Action handler); - } - internal static class NetworkInterfacePal { public static NetworkInterface[] GetAllNetworkInterfaces() => throw new PlatformNotSupportedException(); diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts index 109b6a0c79d99e..fc67eabda69c19 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/exports.ts @@ -72,7 +72,7 @@ import { mono_wasm_bind_cs_function, mono_wasm_get_assembly_exports } from "./in import { mono_wasm_marshal_promise } from "./marshal-to-js"; import { ws_wasm_abort, ws_wasm_close, ws_wasm_create, ws_wasm_open, ws_wasm_receive, ws_wasm_send } from "./web-socket"; import { http_wasm_abort_request, http_wasm_abort_response, http_wasm_create_abort_controler, http_wasm_fetch, http_wasm_fetch_bytes, http_wasm_get_response_bytes, http_wasm_get_response_header_names, http_wasm_get_response_header_values, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes, http_wasm_supports_streaming_response } from "./http"; -import { network_wasm_online, network_wasm_add_change_listener } from "./network-information"; +import { network_wasm_online, network_wasm_set_change_listener, network_wasm_remove_change_listener } from "./network-information"; import { diagnostics } from "./diagnostics"; import { mono_wasm_cancel_promise } from "./cancelable-promise"; import { @@ -489,7 +489,8 @@ const INTERNAL: any = { // NetworkInformation network_wasm_online, - network_wasm_add_change_listener + network_wasm_set_change_listener, + network_wasm_remove_change_listener }; // this represents visibility in the javascript diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts index c0245468c4fb69..fc0a7d16a25355 100644 --- a/src/mono/wasm/runtime/network-information.ts +++ b/src/mono/wasm/runtime/network-information.ts @@ -5,9 +5,32 @@ export function network_wasm_online(): boolean { return globalThis.navigator && globalThis.navigator.onLine; } -export function network_wasm_add_change_listener(listener: (onLine: boolean) => void): void { +let change_listener: ((onLine: boolean) => void) | null = null; + +export function network_wasm_set_change_listener(listener: (onLine: boolean) => void): void { + if (window) { + if (change_listener) { + window.addEventListener("offline", network_wasm_available_changed); + window.addEventListener("online", network_wasm_available_changed); + } + + change_listener = listener; + } +} + +export function network_wasm_remove_change_listener(): void { if (window) { - window.addEventListener("offline", () => listener(network_wasm_online())); - window.addEventListener("online", () => listener(network_wasm_online())); + if (!change_listener) { + window.removeEventListener("offline", network_wasm_available_changed); + window.removeEventListener("online", network_wasm_available_changed); + } + + change_listener = null; + } +} + +function network_wasm_available_changed() { + if (change_listener) { + change_listener(network_wasm_online()); } } From dfa5a6ca9a0f520efb8b43db1b6744d6c4abcae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 14 Jul 2022 09:07:43 +0200 Subject: [PATCH 13/17] Enable more tests. --- .../Net/NetworkInformation/NetworkAddressChange.Browser.cs | 1 + .../tests/FunctionalTests/AddressParsingTests.cs | 1 - .../tests/FunctionalTests/ConnectionsParsingTests.cs | 1 - .../tests/FunctionalTests/DnsParsingTests.cs | 1 - .../tests/FunctionalTests/LoggingTest.cs | 1 - .../tests/FunctionalTests/PhysicalAddressTest.cs | 1 - .../tests/FunctionalTests/StatisticsParsingTests.cs | 1 - 7 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs index 4dcef3de53ea95..435e56d9c53292 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -11,6 +11,7 @@ namespace System.Net.NetworkInformation { + // Browser implementation of NetworkChange public partial class NetworkChange { private static event NetworkAvailabilityChangedEventHandler? s_networkAvailabilityChanged; diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs index 7b01262ade44a2..637cb202fe4362 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/AddressParsingTests.cs @@ -7,7 +7,6 @@ namespace System.Net.NetworkInformation.Tests { - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class AddressParsingTests : FileCleanupTestBase { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs index 911d6cd5c8440a..9f50bf682a9bca 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/ConnectionsParsingTests.cs @@ -6,7 +6,6 @@ namespace System.Net.NetworkInformation.Tests { - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class ConnectionsParsingTests : FileCleanupTestBase { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs index 366a060c79dd18..92d70b6d81a658 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/DnsParsingTests.cs @@ -7,7 +7,6 @@ namespace System.Net.NetworkInformation.Tests { - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class DnsParsingTests : FileCleanupTestBase { [InlineData("NetworkFiles/resolv.conf")] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs index 8c7dcb2569514d..b2c131f76f14b8 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/LoggingTest.cs @@ -6,7 +6,6 @@ namespace System.Net.NetworkInformation.Tests { - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class LoggingTest { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs index b0a17f63aae535..2afabe0f86cde6 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/PhysicalAddressTest.cs @@ -6,7 +6,6 @@ namespace System.Net.NetworkInformation.Tests { - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class PhysicalAddressTest { [Fact] diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs index 4cbc092e679ec7..6187644093f9e1 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/StatisticsParsingTests.cs @@ -6,7 +6,6 @@ namespace System.Net.NetworkInformation.Tests { - [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public class StatisticsParsingTests : FileCleanupTestBase { [Fact] From 1d71019d33404367d125e301518ef9026f772727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 14 Jul 2022 09:30:20 +0200 Subject: [PATCH 14/17] Fix assigning the listener. --- src/mono/wasm/runtime/network-information.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts index fc0a7d16a25355..1b91d019bfbe5c 100644 --- a/src/mono/wasm/runtime/network-information.ts +++ b/src/mono/wasm/runtime/network-information.ts @@ -9,7 +9,7 @@ let change_listener: ((onLine: boolean) => void) | null = null; export function network_wasm_set_change_listener(listener: (onLine: boolean) => void): void { if (window) { - if (change_listener) { + if (!change_listener) { window.addEventListener("offline", network_wasm_available_changed); window.addEventListener("online", network_wasm_available_changed); } @@ -20,7 +20,7 @@ export function network_wasm_set_change_listener(listener: (onLine: boolean) => export function network_wasm_remove_change_listener(): void { if (window) { - if (!change_listener) { + if (change_listener) { window.removeEventListener("offline", network_wasm_available_changed); window.removeEventListener("online", network_wasm_available_changed); } From 23c1eb8afa9d1273d79aa4308c0b08c5416ceb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 14 Jul 2022 09:36:51 +0200 Subject: [PATCH 15/17] Rename network_wasm_online to network_wasm_is_online. --- .../NetworkInformation/BrowserNetworkInterfaceInterop.cs | 2 +- src/mono/wasm/runtime/exports.ts | 4 ++-- src/mono/wasm/runtime/network-information.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs index 834400e42914ef..2df7e6a248a42a 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs @@ -7,7 +7,7 @@ namespace System.Net.NetworkInformation { internal static partial class BrowserNetworkInterfaceInterop { - [JSImport("INTERNAL.network_wasm_online")] + [JSImport("INTERNAL.network_wasm_is_online")] public static partial bool IsOnline(); [JSImport("INTERNAL.network_wasm_set_change_listener")] diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts index fc67eabda69c19..7acc94d357e7c7 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/exports.ts @@ -72,7 +72,7 @@ import { mono_wasm_bind_cs_function, mono_wasm_get_assembly_exports } from "./in import { mono_wasm_marshal_promise } from "./marshal-to-js"; import { ws_wasm_abort, ws_wasm_close, ws_wasm_create, ws_wasm_open, ws_wasm_receive, ws_wasm_send } from "./web-socket"; import { http_wasm_abort_request, http_wasm_abort_response, http_wasm_create_abort_controler, http_wasm_fetch, http_wasm_fetch_bytes, http_wasm_get_response_bytes, http_wasm_get_response_header_names, http_wasm_get_response_header_values, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes, http_wasm_supports_streaming_response } from "./http"; -import { network_wasm_online, network_wasm_set_change_listener, network_wasm_remove_change_listener } from "./network-information"; +import { network_wasm_is_online, network_wasm_set_change_listener, network_wasm_remove_change_listener } from "./network-information"; import { diagnostics } from "./diagnostics"; import { mono_wasm_cancel_promise } from "./cancelable-promise"; import { @@ -488,7 +488,7 @@ const INTERNAL: any = { http_wasm_get_streamed_response_bytes, // NetworkInformation - network_wasm_online, + network_wasm_is_online, network_wasm_set_change_listener, network_wasm_remove_change_listener }; diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts index 1b91d019bfbe5c..4378c0238a7f44 100644 --- a/src/mono/wasm/runtime/network-information.ts +++ b/src/mono/wasm/runtime/network-information.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -export function network_wasm_online(): boolean { +export function network_wasm_is_online(): boolean { return globalThis.navigator && globalThis.navigator.onLine; } @@ -31,6 +31,6 @@ export function network_wasm_remove_change_listener(): void { function network_wasm_available_changed() { if (change_listener) { - change_listener(network_wasm_online()); + change_listener(network_wasm_is_online()); } -} +} \ No newline at end of file From febd72beb071437a9439298f71c5afe8bb2a6875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 18 Jul 2022 14:31:11 +0200 Subject: [PATCH 16/17] Throw when the API is not available. --- .../BrowserNetworkInterfaceInterop.cs | 3 +++ .../NetworkInformation/NetworkAddressChange.Browser.cs | 6 ++++++ .../NetworkInformation/NetworkInterfacePal.Browser.cs | 8 +++++++- .../FunctionalTests/NetworkAvailabilityChangedTests.cs | 10 ++++++++++ .../tests/FunctionalTests/NetworkInterfaceBasicTest.cs | 7 ++++++- src/mono/wasm/runtime/exports.ts | 5 +++-- src/mono/wasm/runtime/network-information.ts | 9 ++++++++- 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs index 2df7e6a248a42a..f0cf9495b79375 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BrowserNetworkInterfaceInterop.cs @@ -7,6 +7,9 @@ namespace System.Net.NetworkInformation { internal static partial class BrowserNetworkInterfaceInterop { + [JSImport("INTERNAL.network_wasm_is_online_api_available")] + public static partial bool IsApiAvailable(); + [JSImport("INTERNAL.network_wasm_is_online")] public static partial bool IsOnline(); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs index 435e56d9c53292..d76954b1bc00b5 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Browser.cs @@ -22,6 +22,9 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC { add { + if (!BrowserNetworkInterfaceInterop.IsApiAvailable()) + throw new System.PlatformNotSupportedException(System.SR.SystemNetNetworkInformation_PlatformNotSupported); + if (s_networkAvailabilityChanged == null) BrowserNetworkInterfaceInterop.SetChangeListener(OnNetworkAvailabilityChanged); @@ -29,6 +32,9 @@ public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityC } remove { + if (!BrowserNetworkInterfaceInterop.IsApiAvailable()) + throw new System.PlatformNotSupportedException(System.SR.SystemNetNetworkInformation_PlatformNotSupported); + s_networkAvailabilityChanged -= value; if (s_networkAvailabilityChanged == null) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs index 6a37b682d021ce..c7328a34d0e91b 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Browser.cs @@ -9,6 +9,12 @@ internal static class NetworkInterfacePal public static int IPv6LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); public static int LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); - public static bool GetIsNetworkAvailable() => BrowserNetworkInterfaceInterop.IsOnline(); + public static bool GetIsNetworkAvailable() + { + if (!BrowserNetworkInterfaceInterop.IsApiAvailable()) + throw new System.PlatformNotSupportedException(System.SR.SystemNetNetworkInformation_PlatformNotSupported); + + return BrowserNetworkInterfaceInterop.IsOnline(); + } } } diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs index ea2cbdc361e204..e7065176369c08 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs @@ -18,6 +18,16 @@ public void NetworkAvailabilityChanged_AddRemove_Success() NetworkChange.NetworkAvailabilityChanged -= _availabilityHandler; } + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))] + public void NetworkAvailabilityChanged_FailsOnNotSupportedPlatform() + { + Assert.Throws(() => + { + NetworkChange.NetworkAvailabilityChanged += _availabilityHandler; + NetworkChange.NetworkAvailabilityChanged -= _availabilityHandler; + }); + } + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] public void NetworkAvailabilityChanged_JustRemove_Success() { diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs index d4c746e5b954f3..d5666c1dae8a60 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs @@ -271,13 +271,18 @@ public void BasicTest_GetIPInterfaceStatistics_Success_Bsd() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] public void BasicTest_GetIsNetworkAvailable_Success() { Assert.True(NetworkInterface.GetIsNetworkAvailable()); } + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))] + public void BasicTest_GetIsNetworkAvailable_FailsOnNotSupportedPlatform() + { + Assert.Throws(() => NetworkInterface.GetIsNetworkAvailable()); + } + [ConditionalTheory] [ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] [SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD, "Expected behavior is different on OSX or FreeBSD")] diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts index 7acc94d357e7c7..fa32042032d388 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/exports.ts @@ -72,7 +72,7 @@ import { mono_wasm_bind_cs_function, mono_wasm_get_assembly_exports } from "./in import { mono_wasm_marshal_promise } from "./marshal-to-js"; import { ws_wasm_abort, ws_wasm_close, ws_wasm_create, ws_wasm_open, ws_wasm_receive, ws_wasm_send } from "./web-socket"; import { http_wasm_abort_request, http_wasm_abort_response, http_wasm_create_abort_controler, http_wasm_fetch, http_wasm_fetch_bytes, http_wasm_get_response_bytes, http_wasm_get_response_header_names, http_wasm_get_response_header_values, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes, http_wasm_supports_streaming_response } from "./http"; -import { network_wasm_is_online, network_wasm_set_change_listener, network_wasm_remove_change_listener } from "./network-information"; +import { network_wasm_is_online, network_wasm_set_change_listener, network_wasm_remove_change_listener, network_wasm_is_online_api_available } from "./network-information"; import { diagnostics } from "./diagnostics"; import { mono_wasm_cancel_promise } from "./cancelable-promise"; import { @@ -490,7 +490,8 @@ const INTERNAL: any = { // NetworkInformation network_wasm_is_online, network_wasm_set_change_listener, - network_wasm_remove_change_listener + network_wasm_remove_change_listener, + network_wasm_is_online_api_available }; // this represents visibility in the javascript diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts index 4378c0238a7f44..b6b59b1b6bb5ba 100644 --- a/src/mono/wasm/runtime/network-information.ts +++ b/src/mono/wasm/runtime/network-information.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. export function network_wasm_is_online(): boolean { - return globalThis.navigator && globalThis.navigator.onLine; + return globalThis.navigator.onLine; } let change_listener: ((onLine: boolean) => void) | null = null; @@ -33,4 +33,11 @@ function network_wasm_available_changed() { if (change_listener) { change_listener(network_wasm_is_online()); } +} + +export function network_wasm_is_online_api_available(): boolean { + return globalThis.navigator + && globalThis.window + && "onLine" in globalThis.navigator + && "addEventListener" in globalThis.window; } \ No newline at end of file From 5ccf469adec38536389a3c4f517a14362826d61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 8 Aug 2022 14:51:46 +0200 Subject: [PATCH 17/17] Feedback. --- src/mono/wasm/runtime/network-information.ts | 31 +++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/mono/wasm/runtime/network-information.ts b/src/mono/wasm/runtime/network-information.ts index b6b59b1b6bb5ba..64aaee2d304f5f 100644 --- a/src/mono/wasm/runtime/network-information.ts +++ b/src/mono/wasm/runtime/network-information.ts @@ -1,32 +1,35 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +import { mono_assert } from "./types"; + export function network_wasm_is_online(): boolean { + mono_assert(network_wasm_is_online_api_available(), "The network_wasm_is_online_api_available is not met"); return globalThis.navigator.onLine; } let change_listener: ((onLine: boolean) => void) | null = null; export function network_wasm_set_change_listener(listener: (onLine: boolean) => void): void { - if (window) { - if (!change_listener) { - window.addEventListener("offline", network_wasm_available_changed); - window.addEventListener("online", network_wasm_available_changed); - } - - change_listener = listener; + mono_assert(network_wasm_is_online_api_available(), "The network_wasm_is_online_api_available is not met"); + + if (!change_listener) { + window.addEventListener("offline", network_wasm_available_changed); + window.addEventListener("online", network_wasm_available_changed); } + + change_listener = listener; } export function network_wasm_remove_change_listener(): void { - if (window) { - if (change_listener) { - window.removeEventListener("offline", network_wasm_available_changed); - window.removeEventListener("online", network_wasm_available_changed); - } - - change_listener = null; + mono_assert(network_wasm_is_online_api_available(), "The network_wasm_is_online_api_available is not met"); + + if (change_listener) { + window.removeEventListener("offline", network_wasm_available_changed); + window.removeEventListener("online", network_wasm_available_changed); } + + change_listener = null; } function network_wasm_available_changed() {