-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SocketAsyncContext should not need to pin Span buffers for sync APIs #46600
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsCurrently, if you call a sync Span-based Socket overload like See references to BufferPtrReceiveOperation and BufferPtrSendOperation in SocketAsyncContext. In theory, this shouldn't be necessary. All sync operation handling happens on the original calling thread, so we can simply hold on to the Span there. The problem is that the structure of the code currently requires that we store this state on the Operation object, which means we need to pin the Span and treat it as a native pointer. We should fix this. This would also allow us to remove the duplication of code that currently exists between the byte[] sync overloads and the Span sync overloads. More generally, we shouldn't really need to store any operation-specific state on the Operation objects for sync operations; it can all live on the calling stack. This would likely simplify the code, and make these operations more efficient since we don't need to allocate an operation each time.
|
We should also find new patterns of code sharing to consolidate sync method duplications in For example |
Currently, if you call a sync Span-based Socket overload like
Socket.Receive(Span<byte> buffer)
, and we end up going through the sync-over-async path in SocketAsyncContext, we will end up pinning the buffer when data is not immediately available from the socket.See references to BufferPtrReceiveOperation and BufferPtrSendOperation in SocketAsyncContext.
In theory, this shouldn't be necessary. All sync operation handling happens on the original calling thread, so we can simply hold on to the Span there. The problem is that the structure of the code currently requires that we store this state on the Operation object, which means we need to pin the Span and treat it as a native pointer.
We should fix this. This would also allow us to remove the duplication of code that currently exists between the byte[] sync overloads and the Span sync overloads.
More generally, we shouldn't really need to store any operation-specific state on the Operation objects for sync operations; it can all live on the calling stack. This would likely simplify the code, and make these operations more efficient since we don't need to allocate an operation each time.
The text was updated successfully, but these errors were encountered: