From 51f22518f0a620a925a994cc1109dd59d24a0c5e Mon Sep 17 00:00:00 2001 From: wfurt Date: Tue, 22 Nov 2022 22:25:19 -0800 Subject: [PATCH 1/2] fix Socket outerloop tests --- .../src/System/Net/Sockets/LingerOption.cs | 7 +++++++ .../src/System/Net/Sockets/Socket.Unix.cs | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs index 17cb04c6db63a..31b4d1cd6e9cf 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs @@ -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() => base.GetHashCode(); } } diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs index 8dba083e1c0ac..70b89071349be 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs @@ -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; From c42562431302ce99f7f91c97ada4072a20c3a791 Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Wed, 23 Nov 2022 10:37:54 -0800 Subject: [PATCH 2/2] Update src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs Co-authored-by: Miha Zupan --- .../System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs index 31b4d1cd6e9cf..3839aa10c166a 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/LingerOption.cs @@ -47,6 +47,6 @@ public override bool Equals(object? comparand) return comparand is LingerOption option && option.Enabled == _enabled && option.LingerTime == _lingerTime; } - public override int GetHashCode() => base.GetHashCode(); + public override int GetHashCode() => HashCode.Combine(_enabled, _lingerTime); } }