Skip to content

Commit a230293

Browse files
authored
Implement Equals & GetHashCode for LingerOption - fix Socket outerloop tests (#78747)
1 parent cbb0323 commit a230293

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ public int LingerTime
4141
_lingerTime = value;
4242
}
4343
}
44+
45+
public override bool Equals(object? comparand)
46+
{
47+
return comparand is LingerOption option && option.Enabled == _enabled && option.LingerTime == _lingerTime;
48+
}
49+
50+
public override int GetHashCode() => HashCode.Combine(_enabled, _lingerTime);
4451
}
4552
}

src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,17 @@ internal Socket CopyStateFromSource(Socket source)
283283
// Try to detect if a property gets added that we're not copying correctly.
284284
foreach (PropertyInfo pi in typeof(Socket).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
285285
{
286-
object? origValue = pi.GetValue(source);
287-
object? cloneValue = pi.GetValue(this);
288-
Debug.Assert(Equals(origValue, cloneValue), $"{pi.Name}. Expected: {origValue}, Actual: {cloneValue}");
286+
try
287+
{
288+
object? origValue = pi.GetValue(source);
289+
object? cloneValue = pi.GetValue(this);
290+
291+
Debug.Assert(Equals(origValue, cloneValue), $"{pi.Name}. Expected: {origValue}, Actual: {cloneValue}");
292+
}
293+
catch (TargetInvocationException ex) when (ex.InnerException is SocketException se && se.SocketErrorCode == SocketError.OperationNotSupported)
294+
{
295+
// macOS fails to retrieve DontFragment and MulticastLoopback at the moment
296+
}
289297
}
290298
#endif
291299
return this;

0 commit comments

Comments
 (0)