Skip to content

Commit

Permalink
Implement Equals & GetHashCode for LingerOption - fix Socket outerloo…
Browse files Browse the repository at this point in the history
…p tests (#78747)
  • Loading branch information
wfurt authored Nov 24, 2022
1 parent cbb0323 commit a230293
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@ public int LingerTime
_lingerTime = value;
}
}

public override bool Equals(object? comparand)
{
return comparand is LingerOption option && option.Enabled == _enabled && option.LingerTime == _lingerTime;
}

public override int GetHashCode() => HashCode.Combine(_enabled, _lingerTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,17 @@ internal Socket CopyStateFromSource(Socket source)
// 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}");
try
{
object? origValue = pi.GetValue(source);
object? cloneValue = pi.GetValue(this);

Debug.Assert(Equals(origValue, cloneValue), $"{pi.Name}. Expected: {origValue}, Actual: {cloneValue}");
}
catch (TargetInvocationException ex) when (ex.InnerException is SocketException se && se.SocketErrorCode == SocketError.OperationNotSupported)
{
// macOS fails to retrieve DontFragment and MulticastLoopback at the moment
}
}
#endif
return this;
Expand Down

0 comments on commit a230293

Please sign in to comment.