Skip to content

Commit

Permalink
[CFHost] Subclass NativeObject + numerous other code updates (#13111)
Browse files Browse the repository at this point in the history
* Subclass NativeObject to reuse object lifetime code.
* Enable nullability and fix code accordingly.
  • Loading branch information
rolfbjarne committed Oct 26, 2021
1 parent fad9779 commit c65bdc7
Showing 1 changed file with 7 additions and 30 deletions.
37 changes: 7 additions & 30 deletions src/CFNetwork/CFHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// Copyright 2012-2015 Xamarin Inc. (http://www.xamarin.com)
//

#nullable enable

using System;
using System.Net;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -43,35 +45,10 @@ namespace CoreServices {
[Obsolete ("Starting with macos12.0 use 'Network.framework' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
#endif
class CFHost : INativeObject, IDisposable {
internal IntPtr handle;

CFHost (IntPtr handle)
{
this.handle = handle;
}

~CFHost ()
{
Dispose (false);
}

public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}

public IntPtr Handle {
get { return handle; }
}

protected virtual void Dispose (bool disposing)
class CFHost : NativeObject {
internal CFHost (IntPtr handle, bool owns)
: base (handle, owns)
{
if (handle != IntPtr.Zero){
CFObject.CFRelease (handle);
handle = IntPtr.Zero;
}
}

[DllImport (Constants.CFNetworkLibrary)]
Expand All @@ -82,7 +59,7 @@ public static CFHost Create (IPEndPoint endpoint)
{
// CFSocketAddress will throw the ANE
using (var data = new CFSocketAddress (endpoint))
return new CFHost (CFHostCreateWithAddress (IntPtr.Zero, data.Handle));
return new CFHost (CFHostCreateWithAddress (IntPtr.Zero, data.Handle), true);
}

[DllImport (Constants.CFNetworkLibrary)]
Expand All @@ -93,7 +70,7 @@ public static CFHost Create (string name)
{
// CFString will throw the ANE
using (var ptr = new CFString (name))
return new CFHost (CFHostCreateWithName (IntPtr.Zero, ptr.Handle));
return new CFHost (CFHostCreateWithName (IntPtr.Zero, ptr.Handle), true);
}
}
}

5 comments on commit c65bdc7

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Packages generated

View packages

Test results

1 tests failed, 217 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)

Pipeline on Agent XAMBOT-1017.BigSur
[CFHost] Subclass NativeObject + numerous other code updates (#13111)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[CFHost] Subclass NativeObject + numerous other code updates (#13111)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[CFHost] Subclass NativeObject + numerous other code updates (#13111)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

✅ Tests passed on macOS M1 - Mac Big Sur (11.5) ✅

Tests passed

All tests on macOS X M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
[CFHost] Subclass NativeObject + numerous other code updates (#13111)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ Tests failed on macOS Mac Mojave (10.14) ❌

Tests failed on Mac Mojave (10.14).

Failed tests are:

  • xammac_tests
  • monotouch-test

Pipeline on Agent
[CFHost] Subclass NativeObject + numerous other code updates (#13111)

Please sign in to comment.