-
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
add SendTo/ReceiveFrom with SocketAddress #88970
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, 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 DetailsAnd uses new SocketAddress API. That spanifies some of the PAL code as prep for removal of Internal.SocketAddress.
|
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
Outdated
Show resolved
Hide resolved
@@ -763,7 +763,7 @@ internal unsafe SocketError DoOperationSendToSingleBuffer(SafeSocketHandle handl | |||
1, | |||
out int bytesTransferred, | |||
_socketFlags, | |||
_socketAddress!.Buffer.AsSpan(), | |||
_socketAddress!.InternalBuffer.AsSpan(), |
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.
Same question as earlier for these... we don't need to splice it down to Size?
// We can fail to get peer address on TCP | ||
socketAddressLen = socketAddress.Length; | ||
SocketAddressPal.Clear(socketAddress); | ||
} |
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.
Is this a bug fix?
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'm not sure but possibly yes. On Windows we seems to get the address but it fails on Linux. Perhaps we can also check if this is TCP and get the value from RemoteEndPoint
? I can write issue for improvement and investigation.
I had trouble because setting Size
zero would throw. Alternatively we can allow it to indicate that the buffer does not have any valid address.
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Outdated
Show resolved
Hide resolved
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.
Other than my comments/questions, LGTM.
I assume SendToAsync / ReceiveFromAsync are coming in a follow-up PR? |
yes. That needs more work to clean up Internal.SocketAddress in socket code. |
this should be ready for another review pass @stephentoub |
@@ -12,7 +12,7 @@ internal static partial class Winsock | |||
[LibraryImport(Interop.Libraries.Ws2_32, SetLastError = true)] | |||
internal static partial SocketError WSAConnect( | |||
SafeSocketHandle socketHandle, | |||
byte[] socketAddress, | |||
Span<byte> socketAddress, |
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 we make the actual LibraryImport private, with an internal wrapper that doesn't take socketAddressSize
? e.g.
[LibraryImport(Interop.Libraries.Ws2_32, SetLastError = true)]
private static partial SocketError WSAConnect(
SafeSocketHandle socketHandle,
Span<byte> socketAddress,
int socketAddressSize,
IntPtr inBuffer,
IntPtr outBuffer,
IntPtr sQOS,
IntPtr gQOS);
internal static SocketError WSAConnect(
SafeSocketHandle socketHandle,
Span<byte> socketAddress,
IntPtr inBuffer,
IntPtr outBuffer,
IntPtr sQOS,
IntPtr gQOS) =>
WSAConnect(socketHandle, socketAddress, socketAddress.Length, inBuffer, outBuffer, sQOS, gQOS);
?
Though reading further that might make it a bit inconsistent with some of the other overloads. It's just a bit strange to see both the span and length passed in.
src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAConnect.cs
Outdated
Show resolved
Hide resolved
perf check
|
And uses new SocketAddress API. That spanifies some of the PAL code as prep for removal of Internal.SocketAddress.
fixes #86872
contributes to #87397
contributes to #30797