[Network] Adopt XAMCORE_4_0 changes in .NET. (#13988)
This commit is contained in:
Родитель
db6a3b278e
Коммит
101c0a7ac0
|
@ -207,7 +207,7 @@ namespace Network {
|
|||
}
|
||||
|
||||
// let to not change the API, but would be nice to remove it in the following releases.
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Uset the 'IndividualChangesDelegate' instead.")]
|
||||
public void SetChangesHandler (Action<NWBrowseResult?, NWBrowseResult?> handler) => IndividualChangesDelegate = handler;
|
||||
#endif
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern OS_nw_protocol_definition nw_protocol_copy_ip_definition ();
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use 'CreateIPDefinition' method instead.")]
|
||||
public static NWProtocolDefinition IPDefinition => new NWProtocolDefinition (nw_protocol_copy_ip_definition (), owns: true);
|
||||
#endif
|
||||
|
@ -66,7 +66,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern OS_nw_protocol_definition nw_protocol_copy_tcp_definition ();
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use 'CreateTcpDefinition' method instead.")]
|
||||
public static NWProtocolDefinition TcpDefinition => new NWProtocolDefinition (nw_protocol_copy_tcp_definition (), owns: true);
|
||||
#endif
|
||||
|
@ -76,7 +76,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern OS_nw_protocol_definition nw_protocol_copy_udp_definition ();
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use 'CreateUdpDefinition' method instead.")]
|
||||
public static NWProtocolDefinition UdpDefinition => new NWProtocolDefinition (nw_protocol_copy_udp_definition (), owns: true);
|
||||
#endif
|
||||
|
@ -86,7 +86,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern OS_nw_protocol_definition nw_protocol_copy_tls_definition ();
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use 'CreateTlsDefinition' method instead.")]
|
||||
public static NWProtocolDefinition TlsDefinition => new NWProtocolDefinition (nw_protocol_copy_tls_definition (), owns: true);
|
||||
#endif
|
||||
|
@ -103,16 +103,9 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
static extern OS_nw_protocol_definition nw_protocol_copy_ws_definition ();
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use 'CreateWebSocketDefinition' method instead.")]
|
||||
[TV (13,0), Mac (10,15), iOS (13,0)]
|
||||
#else
|
||||
[SupportedOSPlatform ("ios13.0")]
|
||||
[SupportedOSPlatform ("tvos13.0")]
|
||||
[SupportedOSPlatform ("macos10.15")]
|
||||
[Obsolete ("Use 'CreateWebSocketDefinition' method instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
|
||||
#endif
|
||||
public static NWProtocolDefinition WebSocketDefinition => new NWProtocolDefinition (nw_protocol_copy_ws_definition (), owns: true);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
internal static extern OS_nw_protocol_metadata nw_ip_create_metadata ();
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWIPMetadata' class and methods instead.")]
|
||||
public static NWProtocolMetadata CreateIPMetadata ()
|
||||
{
|
||||
|
@ -50,8 +50,8 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
internal static extern OS_nw_protocol_metadata nw_udp_create_metadata ();
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
[Obsolete ("Use the 'NSUdpMetadata' class and methods instead.")]
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWUdpMetadata' class and methods instead.")]
|
||||
public static NWProtocolMetadata CreateUdpMetadata ()
|
||||
{
|
||||
return new NWProtocolMetadata (nw_udp_create_metadata (), owns: true);
|
||||
|
@ -131,7 +131,7 @@ namespace Network {
|
|||
throw new InvalidOperationException ("This metadata is not TLS metadata.");
|
||||
}
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWTlsMetadata' class and methods instead.")]
|
||||
public SecProtocolMetadata SecProtocolMetadata => TlsSecProtocolMetadata;
|
||||
|
||||
|
@ -150,7 +150,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
internal static extern NWIPEcnFlag nw_ip_metadata_get_ecn_flag (OS_nw_protocol_metadata metadata);
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWIPMetadata' class and methods instead.")]
|
||||
public NWIPEcnFlag IPMetadataEcnFlag {
|
||||
get {
|
||||
|
@ -167,7 +167,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
internal static extern /* uint64_t */ ulong nw_ip_metadata_get_receive_time (OS_nw_protocol_metadata metadata);
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWIPMetadata' class and methods instead.")]
|
||||
public ulong IPMetadataReceiveTime {
|
||||
get {
|
||||
|
@ -183,7 +183,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
internal static extern NWServiceClass nw_ip_metadata_get_service_class (OS_nw_protocol_metadata metadata);
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWIPMetadata' class and methods instead.")]
|
||||
public NWServiceClass ServiceClass {
|
||||
get => IPServiceClass;
|
||||
|
@ -206,7 +206,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
internal extern static /* uint32_t */ uint nw_tcp_get_available_receive_buffer (IntPtr handle);
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWTcpMetadata' class and methods instead.")]
|
||||
public uint TcpGetAvailableReceiveBuffer ()
|
||||
{
|
||||
|
@ -218,7 +218,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
internal extern static /* uint32_t */ uint nw_tcp_get_available_send_buffer (IntPtr handle);
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the 'NWTcpMetadata' class and methods instead.")]
|
||||
public uint TcpGetAvailableSendBuffer ()
|
||||
{
|
||||
|
|
|
@ -142,7 +142,7 @@ namespace Network {
|
|||
[DllImport (Constants.NetworkLibrary)]
|
||||
extern static IntPtr nw_protocol_stack_copy_internet_protocol (nw_protocol_stack_t stack);
|
||||
|
||||
#if XAMCORE_4_0
|
||||
#if NET
|
||||
public NWProtocolIPOptions? InternetProtocol {
|
||||
#else
|
||||
public NWProtocolOptions? InternetProtocol {
|
||||
|
|
|
@ -129,7 +129,7 @@ namespace Network {
|
|||
delegate bool nw_txt_record_apply_t (IntPtr block, string key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen);
|
||||
unsafe static nw_txt_record_apply_t static_ApplyHandler = TrampolineApplyHandler;
|
||||
|
||||
#if XAMCORE_4_0
|
||||
#if NET
|
||||
public delegate bool NWTxtRecordApplyDelegate (string key, NWTxtRecordFindKey result, ReadOnlySpan<byte> value);
|
||||
#else
|
||||
public delegate void NWTxtRecordApplyDelegate (string key, NWTxtRecordFindKey rersult, ReadOnlySpan<byte> value);
|
||||
|
@ -139,7 +139,7 @@ namespace Network {
|
|||
[MonoPInvokeCallback (typeof (nw_txt_record_apply_t))]
|
||||
unsafe static bool TrampolineApplyHandler (IntPtr block, string key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen)
|
||||
{
|
||||
#if XAMCORE_4_0
|
||||
#if NET
|
||||
var del = BlockLiteral.GetTarget<NWTxtRecordApplyDelegate> (block);
|
||||
#else
|
||||
var del = BlockLiteral.GetTarget<MulticastDelegate> (block);
|
||||
|
@ -148,7 +148,7 @@ namespace Network {
|
|||
return false;
|
||||
|
||||
var mValue = new ReadOnlySpan<byte> ((void*)value, (int)valueLen);
|
||||
#if XAMCORE_4_0
|
||||
#if NET
|
||||
return del (key, found, mValue);
|
||||
#else
|
||||
if (del is NWTxtRecordApplyDelegate apply) {
|
||||
|
@ -162,7 +162,7 @@ namespace Network {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[Obsolete ("Use the overload that takes an NWTxtRecordApplyDelegate2 instead.")]
|
||||
#endif
|
||||
[BindingImpl (BindingImplOptions.Optimizable)]
|
||||
|
@ -180,7 +180,7 @@ namespace Network {
|
|||
}
|
||||
}
|
||||
|
||||
#if !XAMCORE_4_0
|
||||
#if !NET
|
||||
[BindingImpl (BindingImplOptions.Optimizable)]
|
||||
public bool Apply (NWTxtRecordApplyDelegate2 handler)
|
||||
{
|
||||
|
|
|
@ -97,7 +97,11 @@ namespace MonoTouchFixtures.Network {
|
|||
if (st == NWBrowserState.Ready)
|
||||
browserReady.Set ();
|
||||
});
|
||||
#if NET
|
||||
browser.IndividualChangesDelegate = (oldResult, newResult) => {
|
||||
#else
|
||||
browser.SetChangesHandler ((oldResult, newResult) => {
|
||||
#endif
|
||||
didRun = true;
|
||||
try {
|
||||
receivedNotNullChange = oldResult != null || newResult != null;
|
||||
|
@ -107,8 +111,11 @@ namespace MonoTouchFixtures.Network {
|
|||
changesEvent.Set ();
|
||||
eventsDone = true;
|
||||
}
|
||||
|
||||
#if NET
|
||||
};
|
||||
#else
|
||||
});
|
||||
#endif
|
||||
browser.Start ();
|
||||
browserReady.WaitOne (30000);
|
||||
using (var advertiser = NWAdvertiseDescriptor.CreateBonjourService ("MonoTouchFixtures.Network", type))
|
||||
|
|
|
@ -18,28 +18,28 @@ namespace MonoTouchFixtures.Network {
|
|||
[Test]
|
||||
public void IPDefinitionTest ()
|
||||
{
|
||||
using (var definition = NWProtocolDefinition.IPDefinition)
|
||||
using (var definition = NWProtocolDefinition.CreateIPDefinition ())
|
||||
Assert.NotNull (definition);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TcpDefinitionTest ()
|
||||
{
|
||||
using (var definition = NWProtocolDefinition.TcpDefinition)
|
||||
using (var definition = NWProtocolDefinition.CreateTcpDefinition ())
|
||||
Assert.NotNull (definition);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TlsDefinitionTest ()
|
||||
{
|
||||
using (var definition = NWProtocolDefinition.TlsDefinition)
|
||||
using (var definition = NWProtocolDefinition.CreateTlsDefinition ())
|
||||
Assert.NotNull (definition);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UdpDefinitionTest ()
|
||||
{
|
||||
using (var definition = NWProtocolDefinition.UdpDefinition)
|
||||
using (var definition = NWProtocolDefinition.CreateUdpDefinition ())
|
||||
Assert.NotNull (definition);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace MonoTouchFixtures.Network {
|
|||
public void WebSocketDefinitionTest ()
|
||||
{
|
||||
TestRuntime.AssertXcodeVersion (11, 0);
|
||||
using (var definition = NWProtocolDefinition.WebSocketDefinition)
|
||||
using (var definition = NWProtocolDefinition.CreateWebSocketDefinition ())
|
||||
Assert.NotNull (definition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,34 +20,50 @@ namespace MonoTouchFixtures.Network {
|
|||
[Test]
|
||||
public void IP ()
|
||||
{
|
||||
#if NET
|
||||
using (var m = new NWIPMetadata ()) {
|
||||
Assert.That (m.EcnFlag, Is.EqualTo (NWIPEcnFlag.NonEct), "IPMetadataEcnFlag");
|
||||
Assert.That (m.ReceiveTime, Is.EqualTo (TimeSpan.Zero), "IPMetadataReceiveTime");
|
||||
#else
|
||||
using (var m = NWProtocolMetadata.CreateIPMetadata ()) {
|
||||
Assert.That (m.IPMetadataEcnFlag, Is.EqualTo (NWIPEcnFlag.NonEct), "IPMetadataEcnFlag");
|
||||
Assert.That (m.IPMetadataReceiveTime, Is.EqualTo (0), "IPMetadataReceiveTime");
|
||||
#endif
|
||||
Assert.True (m.IsIP, "IsIP");
|
||||
Assert.False (m.IsTcp, "IsTcp");
|
||||
Assert.False (m.IsUdp, "IsUdp");
|
||||
Assert.NotNull (m.ProtocolDefinition, "ProtocolDefinition");
|
||||
#if !NET
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.SecProtocolMetadata; }, "SecProtocolMetadata");
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.TlsSecProtocolMetadata; }, "TlsSecProtocolMetadata");
|
||||
#endif
|
||||
Assert.That (m.ServiceClass, Is.EqualTo (NWServiceClass.BestEffort), "ServiceClass");
|
||||
#if !NET
|
||||
Assert.That (m.IPServiceClass, Is.EqualTo (NWServiceClass.BestEffort), "IPServiceClass");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Udp ()
|
||||
{
|
||||
#if NET
|
||||
using (var m = new NWUdpMetadata ()) {
|
||||
#else
|
||||
using (var m = NWProtocolMetadata.CreateUdpMetadata ()) {
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.IPMetadataEcnFlag; }, "IPMetadataEcnFlag");
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.IPMetadataReceiveTime; }, "IPMetadataReceiveTime");
|
||||
#endif
|
||||
Assert.False (m.IsIP, "IsIP");
|
||||
Assert.False (m.IsTcp, "IsTcp");
|
||||
Assert.True (m.IsUdp, "IsUdp");
|
||||
Assert.NotNull (m.ProtocolDefinition, "ProtocolDefinition");
|
||||
#if !NET
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.SecProtocolMetadata; }, "SecProtocolMetadata");
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.TlsSecProtocolMetadata; }, "TlsSecProtocolMetadata");
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.ServiceClass; }, "ServiceClass");
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.IPServiceClass; }, "IPServiceClass");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,18 +71,28 @@ namespace MonoTouchFixtures.Network {
|
|||
public void Quic ()
|
||||
{
|
||||
TestRuntime.AssertXcodeVersion (13,0);
|
||||
#if NET
|
||||
using (var m = new NWIPMetadata ()) {
|
||||
Assert.That (m.EcnFlag, Is.EqualTo (NWIPEcnFlag.NonEct), "IPMetadataEcnFlag");
|
||||
Assert.That (m.ReceiveTime, Is.EqualTo (TimeSpan.Zero), "IPMetadataReceiveTime");
|
||||
#else
|
||||
using (var m = NWProtocolMetadata.CreateIPMetadata ()) {
|
||||
Assert.That (m.IPMetadataEcnFlag, Is.EqualTo (NWIPEcnFlag.NonEct), "IPMetadataEcnFlag");
|
||||
Assert.That (m.IPMetadataReceiveTime, Is.EqualTo (0), "IPMetadataReceiveTime");
|
||||
#endif
|
||||
Assert.True (m.IsIP, "IsIP");
|
||||
Assert.False (m.IsTcp, "IsTcp");
|
||||
Assert.False (m.IsUdp, "IsUdp");
|
||||
Assert.False (m.IsQuic, "IsQuic");
|
||||
Assert.NotNull (m.ProtocolDefinition, "ProtocolDefinition");
|
||||
#if !NET
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.SecProtocolMetadata; }, "SecProtocolMetadata");
|
||||
Assert.Throws<InvalidOperationException> (() => { var x = m.TlsSecProtocolMetadata; }, "TlsSecProtocolMetadata");
|
||||
#endif
|
||||
Assert.That (m.ServiceClass, Is.EqualTo (NWServiceClass.BestEffort), "ServiceClass");
|
||||
#if !NET
|
||||
Assert.That (m.IPServiceClass, Is.EqualTo (NWServiceClass.BestEffort), "IPServiceClass");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,18 +116,22 @@ namespace MonoTouchFixtures.Network
|
|||
record.Add (key, key);
|
||||
}
|
||||
// apply and ensure that we do get all the keys
|
||||
#if !NET
|
||||
var keyCount = 0;
|
||||
record.Apply ((k, r, v) => {
|
||||
keyCount++;
|
||||
Assert.IsTrue (keys.Contains (k), k);
|
||||
});
|
||||
#endif
|
||||
var keyCount2 = 0;
|
||||
record.Apply ((k, r, v) => {
|
||||
keyCount2++;
|
||||
Assert.IsTrue (keys.Contains (k), k);
|
||||
return true;
|
||||
});
|
||||
#if !NET
|
||||
Assert.AreEqual (keys.Count, keyCount, "keycount");
|
||||
#endif
|
||||
Assert.AreEqual (keys.Count, keyCount2, "keycount2");
|
||||
}
|
||||
|
||||
|
|
|
@ -58,8 +58,13 @@ namespace MonoTouchFixtures.Security {
|
|||
// Wait until the connection is ready.
|
||||
Assert.True (ready.WaitOne (TimeSpan.FromSeconds (10)), "Connection is ready");
|
||||
|
||||
#if NET
|
||||
using (var m = connection.GetProtocolMetadata<NWTlsMetadata> (NWProtocolDefinition.CreateTlsDefinition ())) {
|
||||
var s = m.SecProtocolMetadata;
|
||||
#else
|
||||
using (var m = connection.GetProtocolMetadata (NWProtocolDefinition.TlsDefinition)) {
|
||||
var s = m.TlsSecProtocolMetadata;
|
||||
#endif
|
||||
Assert.False (s.EarlyDataAccepted, "EarlyDataAccepted");
|
||||
#if !NET
|
||||
Assert.That (s.NegotiatedCipherSuite, Is.Not.EqualTo (SslCipherSuite.SSL_NULL_WITH_NULL_NULL), "NegotiatedCipherSuite");
|
||||
|
|
Загрузка…
Ссылка в новой задаче