Skip to content

Commit

Permalink
[CoreFoundation] Make P/Invokes in CFSocket have blittable signatures. (
Browse files Browse the repository at this point in the history
#20162)

Contributes towards #15684.
  • Loading branch information
rolfbjarne authored Feb 22, 2024
1 parent dbbf9c3 commit a231083
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/CoreFoundation/CFSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,17 @@ public CFSocket (AddressFamily family, SocketType type, ProtocolType proto, CFRu
internal CFSocket (CFSocketSignature sig, double timeout)
{
unsafe {
#if NET
Initialize (
CFRunLoop.Current,
(CFSocketContext* ctx) => CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, ref sig, (nuint) (ulong) defaultCallbackTypes, &OnCallback, ctx, timeout)
);
(CFSocketContext* ctx) => {
CFSocketSignature localSig = sig;
#if NET
return CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, &localSig, (nuint) (ulong) defaultCallbackTypes, &OnCallback, ctx, timeout);
#else
Initialize (
CFRunLoop.Current,
(CFSocketContext* ctx) => CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, ref sig, (nuint) (ulong) defaultCallbackTypes, OnCallback, ctx, timeout)
);
return CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, &localSig, (nuint) (ulong) defaultCallbackTypes, OnCallback, ctx, timeout);
#endif
}
);
}
}

Expand Down Expand Up @@ -496,13 +496,13 @@ void Initialize (CFRunLoop runLoop, CreateSocket createSocket)

#if NET
[DllImport (Constants.CoreFoundationLibrary)]
unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, ref CFSocketSignature signature,
unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, CFSocketSignature* signature,
nuint /*CFOptionFlags*/ callBackTypes,
delegate* unmanaged<IntPtr, nuint, IntPtr, IntPtr, IntPtr, void> callout,
CFSocketContext* context, double timeout);
#else
[DllImport (Constants.CoreFoundationLibrary)]
unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, ref CFSocketSignature signature,
unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, CFSocketSignature* signature,
nuint /*CFOptionFlags*/ callBackTypes,
CFSocketCallBack callout,
CFSocketContext* context, double timeout);
Expand Down
1 change: 0 additions & 1 deletion tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ public partial class BlittablePInvokes {
"System.IntPtr CoreFoundation.CFPropertyList::CFPropertyListCreateData(System.IntPtr,System.IntPtr,System.IntPtr,System.UIntPtr,System.IntPtr&)",
"System.IntPtr CoreFoundation.CFPropertyList::CFPropertyListCreateWithData(System.IntPtr,System.IntPtr,System.UIntPtr,System.IntPtr&,System.IntPtr&)",
"System.IntPtr CoreFoundation.CFRunLoopSourceCustom::CFRunLoopSourceCreate(System.IntPtr,System.IntPtr,CoreFoundation.CFRunLoopSourceContext&)",
"System.IntPtr CoreFoundation.CFSocket::CFSocketCreateConnectedToSocketSignature(System.IntPtr,CoreFoundation.CFSocketSignature&,System.UIntPtr,method System.Void *(System.IntPtr,System.UIntPtr,System.IntPtr,System.IntPtr,System.IntPtr),CoreFoundation.CFSocketContext*,System.Double)",
"System.IntPtr CoreFoundation.CFUrl::CFURLCreateWithFileSystemPath(System.IntPtr,System.IntPtr,System.IntPtr,System.Boolean)",
"System.IntPtr CoreFoundation.DispatchData::dispatch_data_create_map(System.IntPtr,System.IntPtr&,System.UIntPtr&)",
"System.IntPtr CoreGraphics.CGEvent::CGEventCreateKeyboardEvent(System.IntPtr,System.UInt16,System.Boolean)",
Expand Down

7 comments on commit a231083

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.