mgravell / Pipelines.Sockets.Unofficial

.NET managed sockets wrapper using the new "Pipelines" API
Other
412 stars 54 forks source link

net7 cleanup and fix broken pinned/unmanaged flag detection #74

Closed mgravell closed 1 year ago

mgravell commented 1 year ago

the primary change here is to make AOT work, by removing any ref-emit, evil poking, or usage of MakeGenericType/MakeGenericMethod. This last required removing some T : unmanaged constraints (which is why we were using generics, because those scenarios couldn't be known statically), instead using evilness to keep things working - not least, a re-implementation of MemoryMarshal.Cast<TFrom, TTo> without the TFrom : struct, TTo : struct constraints (runtime checked, though) using MemoryMarshal.CreateSpan (note: on down-level TFMs, uses MakeGenericMethod to use the inbuilt Cast method, but that's fine: we don't need AOT on those platforms)

also:

mgravell commented 1 year ago

Re function pointers: partly perf, partly to avoid having to declare the type etc (can't use generics with spans), partly because they rock

On Wed, 3 May 2023, 16:01 Eric Erhardt, @.***> wrote:

@.**** approved this pull request.

Nice work! This is awesome. Thanks for making this library AOT-compatible.

In tests/AotTests/AotTests.csproj https://github.com/mgravell/Pipelines.Sockets.Unofficial/pull/74#discussion_r1183792683 :

@@ -0,0 +1,17 @@ + +

  • Exe
  • net7.0
  • enable
  • true

⬇️ Suggested change

-

  • true

In src/Pipelines.Sockets.Unofficial/Arenas/PerTypeHelpers.cs https://github.com/mgravell/Pipelines.Sockets.Unofficial/pull/74#discussion_r1183811274 :

  • Cast = (delegate*<Span, Span>)concrete.MethodHandle.GetFunctionPointer();
  • }
  • //Cast = (CastHelper)Delegate.CreateDelegate(typeof(CastHelper), null, concrete);

(for my learning) Why function pointers here instead of a normal delegate?

— Reply to this email directly, view it on GitHub https://github.com/mgravell/Pipelines.Sockets.Unofficial/pull/74#pullrequestreview-1411067193, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEHMDNCPKCCGDDSWQLXTDXEJXNJANCNFSM6AAAAAAXTE2UUA . You are receiving this because you authored the thread.Message ID: @.*** com>

mgravell commented 1 year ago

v2.2.8 should be available

lukebakken commented 1 year ago

Thanks! I've been studying this and your other projects @mgravell to improve the RabbitMQ .NET client.