-
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
adding span version of ReceiveMessageFrom #46285
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/ncl Issue DetailsI followed the other examples of overloads with span and it seems like the normal is duplication of code, since the other methods are not that long. Should I keep it like this or call the span version from the byte[] version, and remove some of the duplication? fix #43933
|
6637616
to
c5df76f
Compare
thanks for the contribution @ovebastiansen. It seems like you simply duplicated all the code we use with |
c5df76f
to
c13e3fe
Compare
/azp run runtime |
Commenter does not have sufficient privileges for PR 46285 in repo dotnet/runtime |
47ba28d
to
a3961ab
Compare
It's kind of weird to add this just for ReceiveMessageFrom, but not ReceiveFrom or SendTo. I don't think we'd want to ship 6.0 like that. |
I can fix those two as well then in this PR. Does the code otherwise look ok now? |
The reason we have duplication in a lot of these cases is because the sync implementation in SocketAsyncContext ends up treating In theory the code shouldn't need to do this pinning, but it that's a separate issue and isn't trivial to fix. Addign @stephentoub in case he has any thoughts to add. |
does that mean I should duplicate or keep it like this? |
Unfortunately, I think it means we should duplicate the code in the same way we do for Receive today. That is, the byte[] overload should use byte[] all the way down and not pin, and the Span overload should use Span all the way down, and pin when it creates the Operation object. It would be good to fix this in the future; I'll file a separate issue on this. |
We need tests for these overloads too. Adding @antonfirsov who has looked at these tests most recently. Anton, what's the best way to test these new overloads? |
Ok, then I will go back to the first implementation, with the duplication. And I will also try to fix the other two methods you mentioned. I just figured they where tracked somewhere else in the sockets mega issue ;) |
Yeah, they are all tracked in #43935 |
I added an issue re Span and pinning and code duplication, here: #46600 |
a3961ab
to
f2c2a3d
Compare
#46862 from @antonfirsov should make testing this easy, we just need to ensure we have the right hooks enabled for the new overloads. |
Sorry, despite the tagging I somehow missed this PR 😞 I also didn't think through the fact that there is no span overload for runtime/src/libraries/System.Net.Sockets/tests/FunctionalTests/ReceiveMessageFrom.cs Lines 156 to 159 in e464963
On master, that test is now duplicate of the array test. In order to make pick up the span overload, runtime/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketTestHelper.cs Lines 413 to 421 in e464963
This should be sufficient to provide the necessary test coverage for this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good after some cleanup, updating the tests and removing the code duplication in the Windows PAL.
I have a few (optional) suggestions though.
|
||
namespace System.Net.Sockets.Tests | ||
{ | ||
public class ReceiveMessageFromSpan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole class can be deleted now in favor of the SocketTestHelperSpan
extension suggested in #46285 (comment).
However, in order to stress slicing, I would alter ReceiveSentMessages_Success
to use an ArraySegment
with a non-zero offset as a receiveBuffer
:
runtime/src/libraries/System.Net.Sockets/tests/FunctionalTests/ReceiveMessageFrom.cs
Line 36 in 699f49a
byte[] receiveBuffer = new byte[DatagramSize]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried adding a bigger array receive array and offset it. Mostly seems to be working, checking that the part before the offset is not written to, and that the rest is the same. But now the EAP version fails, somewhere in the code it does not respect the offset it seems, and just tries to write to the start of the array. I have looked at the entrypart of the code and cannot spot an easy reason for this. Can you check it, @antonfirsov?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antonfirsov Where you able to spot any problems in this? EAP tests fails when running with an offset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ovebastiansen I'm sorry, missed your original comment, looks like a bug, opened an issue: #47637.
Please modify the beginning of your test as following, so you are not blocked by this:
// [ActiveIssue("https://github.com/dotnet/runtime/issues/47637")]
int offset = UsesSync ? 10 : 0;
Edit: There was a typo in the original suggestion. Should be UsesSync ? 10 : 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better if you do it like: UsesSync || !PlatformDetection.IsWindows ? 10 : 0
src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs
Outdated
Show resolved
Hide resolved
@@ -1564,6 +1564,73 @@ public int ReceiveMessageFrom(byte[] buffer, int offset, int size, ref SocketFla | |||
return bytesTransferred; | |||
} | |||
|
|||
public int ReceiveMessageFrom(Span<byte> buffer, ref SocketFlags socketFlags, ref EndPoint remoteEP, out IPPacketInformation ipPacketInformation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it seems like non of the other methods in this class has it, should I start the it or am I looking at the wrong place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check #47230 and #47229 as examples adding new methods to Socket.cs
together with xml docs.
Just copy existing docs, and modify them according to the new overload:
https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receivemessagefrom?view=net-5.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
took a stab at the documentation, copied from the existing, but existing is missing some of the exception actually thrown from the method, so a bit unsure if they should be added.
f2c2a3d
to
2666248
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are good to merge after fixing the merge conflicts and adding the xml docs.
The conflicts are coming from recent PR-s around the area, and I don't expect them to be hard to fix.
@ovebastiansen I opened #47642 to fix the async Windows bug, if it gets merged before your PR, you don't need to bother with the |
7bd0275
to
57c84d3
Compare
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after fixing two nits.
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs
Outdated
Show resolved
Hide resolved
Test failure is in the latest (inner) run is #47728. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized we still need to fix stuff in xmldocs, for example adding a copy of the long remarks section of the array overload. Regardless, I want to merge this as-is to unblock follow-up work, and will rather open a separate PR with the docs myself instead of delaying this PR further. new-api-needs-documentation
PR-s contain an unfair amount of formal expectations towards community contributors IMO. @carlossanlop thoughts on this?
@ovebastiansen thanks for the work and the patience!
I followed the other examples of overloads with span and it seems like the normal is duplication of code, since the other methods are not that long. Should I keep it like this or call the span version from the byte[] version, and remove some of the duplication?
fix #43933