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

fix DualMode ReceiveFrom on macOS #78261

Merged
merged 6 commits into from
Nov 23, 2022
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 @@ -280,13 +280,16 @@ internal Socket CopyStateFromSource(Socket source)
_pendingConnectRightEndPoint = source._pendingConnectRightEndPoint;
_singleBufferReceiveEventArgs = source._singleBufferReceiveEventArgs;
#if DEBUG
/*
// Try to detect if a property gets added that we're not copying correctly.
foreach (PropertyInfo pi in typeof(Socket).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
object? origValue = pi.GetValue(source);
object? cloneValue = pi.GetValue(this);
Debug.Assert(Equals(origValue, cloneValue), $"{pi.Name}. Expected: {origValue}, Actual: {cloneValue}");
//Debug.Assert(Equals(origValue, cloneValue), $"{pi.Name}. Expected: {origValue}, Actual: {cloneValue}");
}
*/
antonfirsov marked this conversation as resolved.
Show resolved Hide resolved

#endif
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ public int ReceiveMessageFrom(byte[] buffer, int offset, int size, ref SocketFla
ValidateBufferArguments(buffer, offset, size);
ValidateReceiveFromEndpointAndState(remoteEP, nameof(remoteEP));

SocketPal.CheckDualModeReceiveSupport(this);
SocketPal.CheckDualModePacketInfoSupport(this);
ValidateBlockingMode();

// We don't do a CAS demand here because the contents of remoteEP aren't used by
Expand Down Expand Up @@ -1632,7 +1632,7 @@ public int ReceiveMessageFrom(Span<byte> buffer, ref SocketFlags socketFlags, re
throw new InvalidOperationException(SR.net_sockets_mustbind);
}

SocketPal.CheckDualModeReceiveSupport(this);
SocketPal.CheckDualModePacketInfoSupport(this);
ValidateBlockingMode();

// We don't do a CAS demand here because the contents of remoteEP aren't used by
Expand Down Expand Up @@ -1795,8 +1795,6 @@ public int ReceiveFrom(Span<byte> buffer, SocketFlags socketFlags, ref EndPoint
ThrowIfDisposed();
ValidateReceiveFromEndpointAndState(remoteEP, nameof(remoteEP));

SocketPal.CheckDualModeReceiveSupport(this);

ValidateBlockingMode();

// We don't do a CAS demand here because the contents of remoteEP aren't used by
Expand Down Expand Up @@ -2933,7 +2931,7 @@ private bool ReceiveMessageFromAsync(SocketAsyncEventArgs e, CancellationToken c
throw new ArgumentException(SR.Format(SR.net_InvalidEndPointAddressFamily, e.RemoteEndPoint.AddressFamily, _addressFamily), nameof(e));
}

SocketPal.CheckDualModeReceiveSupport(this);
SocketPal.CheckDualModePacketInfoSupport(this);

// We don't do a CAS demand here because the contents of remoteEP aren't used by
// WSARecvMsg; all that matters is that we generate a unique-to-this-call SocketAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static SocketError GetSocketErrorForErrorCode(Interop.Error errorCode)
return SocketErrorPal.GetSocketErrorForNativeError(errorCode);
}

public static void CheckDualModeReceiveSupport(Socket socket)
public static void CheckDualModePacketInfoSupport(Socket socket)
{
if (!SupportsDualModeIPv4PacketInfo && socket.AddressFamily == AddressFamily.InterNetworkV6 && socket.DualMode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ private static unsafe bool TransmitFileHelper(
}

[Conditional("unnecessary")]
public static void CheckDualModeReceiveSupport(Socket socket)
public static void CheckDualModePacketInfoSupport(Socket socket)
{
// Dual-mode sockets support received packet info on Windows.
}
Expand Down
5 changes: 5 additions & 0 deletions src/native/libs/System.Native/pal_networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,8 +1399,13 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade
ConvertMessageHeaderToMsghdr(&header, messageHeader, fd);

ssize_t res;
printf("%s:%d: recvmsg name %p %d socksize=%zd\n", __func__, __LINE__, header.msg_name, header.msg_namelen, sizeof(struct sockaddr_in6));
while ((res = recvmsg(fd, &header, socketFlags)) < 0 && errno == EINTR);

printf("%s:%d: recvmsg finished with %zd name %p %d\n", __func__, __LINE__, res, header.msg_name, header.msg_namelen);
printf("%s:%d: poer=%du addr (%s)\n", __func__, __LINE__, ((struct sockaddr_in*)header.msg_name)->sin_port, inet_ntoa(((struct sockaddr_in*)header.msg_name)->sin_addr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also looks like leftover from local debugging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you see it @antonfirsov. This was removed yesterday in 70a11fa

Copy link
Member

@antonfirsov antonfirsov Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea how I ended up commenting on the outdated variant.



assert(header.msg_name == messageHeader->SocketAddress); // should still be the same location as set in ConvertMessageHeaderToMsghdr
assert(header.msg_control == messageHeader->ControlBuffer);

Expand Down