Skip to content
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

only slice SocketAddress on success operation #90284

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ protected override bool DoTryComplete(SocketAsyncContext context)
else
{
bool result = SocketPal.TryCompleteReceiveFrom(context._socket, Buffer.Span, null, Flags, SocketAddress.Span, out int socketAddressLen, out BytesTransferred, out ReceivedFlags, out ErrorCode);
SocketAddress = SocketAddress.Slice(0, socketAddressLen);
if (ErrorCode == SocketError.Success)
{
SocketAddress = SocketAddress.Slice(0, socketAddressLen);
}
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,7 @@ private static SocketError FinishOperationConnect()

private void UpdateReceivedSocketAddress(SocketAddress socketAddress)
{
if (_socketAddressSize > 0)
{
socketAddress.Size = _socketAddressSize;
}
socketAddress.Size = _socketAddressSize;
}

partial void FinishOperationReceiveMessageFrom();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ private static unsafe int SysReceive(SafeSocketHandle socket, SocketFlags flags,
Count = (UIntPtr)buffer.Length
};

if (socketAddress.Length == 0)
{
Debug.Assert(sockAddr == null);
}

var messageHeader = new Interop.Sys.MessageHeader {
SocketAddress = sockAddr,
SocketAddressLen = socketAddress.Length,
Expand Down Expand Up @@ -468,7 +473,6 @@ private static unsafe int SysReceive(SafeSocketHandle socket, SocketFlags flags,
private static unsafe int SysReceiveMessageFrom(SafeSocketHandle socket, SocketFlags flags, Span<byte> buffer, Span<byte> socketAddress, out int socketAddressLen, bool isIPv4, bool isIPv6, out SocketFlags receivedFlags, out IPPacketInformation ipPacketInformation, out Interop.Error errno)
{
Debug.Assert(socket.IsSocket);
Debug.Assert(socketAddress != null, "Expected non-null socketAddress");

int cmsgBufferLen = Interop.Sys.GetControlMessageBufferSize(Convert.ToInt32(isIPv4), Convert.ToInt32(isIPv6));
byte* cmsgBuffer = stackalloc byte[cmsgBufferLen];
Expand All @@ -484,6 +488,11 @@ private static unsafe int SysReceiveMessageFrom(SafeSocketHandle socket, SocketF
Count = (UIntPtr)buffer.Length
};

if (socketAddress.Length == 0)
{
Debug.Assert(rawSocketAddress == null);
}

messageHeader = new Interop.Sys.MessageHeader {
SocketAddress = rawSocketAddress,
SocketAddressLen = socketAddress.Length,
Expand Down Expand Up @@ -1234,7 +1243,7 @@ public static SocketError Receive(SafeSocketHandle handle, IList<ArraySegment<by
}
else
{
if (!TryCompleteReceiveFrom(handle, buffers, socketFlags, null, out int _, out bytesTransferred, out _, out errorCode))
if (!TryCompleteReceiveFrom(handle, buffers, socketFlags, Span<byte>.Empty, out int _, out bytesTransferred, out _, out errorCode))
{
errorCode = SocketError.WouldBlock;
}
Expand Down