From ae4530c1f4e36c9741e5538c8a62756fb93da467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Mon, 29 Aug 2022 12:33:46 +0300 Subject: [PATCH 1/8] API: Constructor with string? for SocketException --- .../ref/System.Net.Primitives.cs | 1 + .../src/System/Net/SocketException.cs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs index 00250e07d8f328..6f2dca85a1b6d0 100644 --- a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs +++ b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs @@ -471,6 +471,7 @@ public partial class SocketException : System.ComponentModel.Win32Exception { public SocketException() { } public SocketException(int errorCode) { } + public SocketException(int errorCode, string? message) { } protected SocketException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } public override int ErrorCode { get { throw null; } } public override string Message { get { throw null; } } diff --git a/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs b/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs index 3e5540419d03b1..94417d2dddc733 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs @@ -30,12 +30,23 @@ public SocketException(int errorCode) : this((SocketError)errorCode) // but that's the least bad option right now. } + /// Creates a new instance of the class with the specified error code and optional message. + public SocketException(int errorCode, string? message) : this((SocketError)errorCode, message) + { + } + /// Creates a new instance of the class with the specified error code as SocketError. internal SocketException(SocketError socketError) : base(GetNativeErrorForSocketError(socketError)) { _errorCode = socketError; } + /// Creates a new instance of the class with the specified error code as SocketError and optional message. + internal SocketException(SocketError socketError, string? message) : base(GetNativeErrorForSocketError(socketError), message) + { + _errorCode = socketError; + } + public override string Message => base.Message; public SocketError SocketErrorCode => _errorCode; From 86a7f92ef4f28a02b06527f6b8af2fc0e7b09c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Mon, 29 Aug 2022 16:07:21 +0300 Subject: [PATCH 2/8] Update: Review changes Co-authored-by: Anton Firszov --- .../System.Net.Primitives/src/System/Net/SocketException.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs b/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs index 94417d2dddc733..46f4d4305124b3 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs @@ -30,7 +30,7 @@ public SocketException(int errorCode) : this((SocketError)errorCode) // but that's the least bad option right now. } - /// Creates a new instance of the class with the specified error code and optional message. + /// Initializes a new instance of the class with the specified error code and optional message. public SocketException(int errorCode, string? message) : this((SocketError)errorCode, message) { } @@ -41,7 +41,7 @@ internal SocketException(SocketError socketError) : base(GetNativeErrorForSocket _errorCode = socketError; } - /// Creates a new instance of the class with the specified error code as SocketError and optional message. + /// Initializes a new instance of the class with the specified error code as SocketError and optional message. internal SocketException(SocketError socketError, string? message) : base(GetNativeErrorForSocketError(socketError), message) { _errorCode = socketError; From 523ad8a10d4b2e1d8920893731bb3b7b5a36fb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Tue, 30 Aug 2022 09:04:34 +0300 Subject: [PATCH 3/8] Update: ExtendedSocketException deleted, added few tests --- .../Internals/SocketExceptionFactory.Unix.cs | 2 +- .../Net/Internals/SocketExceptionFactory.cs | 22 +------- .../FunctionalTests/SocketExceptionTest.cs | 53 +++++++++++++++++++ ...tem.Net.Primitives.Functional.Tests.csproj | 4 +- 4 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs diff --git a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs b/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs index 88e5af18ba215c..945424a9edf6f9 100644 --- a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs +++ b/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs @@ -9,7 +9,7 @@ internal static partial class SocketExceptionFactory { public static SocketException CreateSocketException(SocketError errorCode, int platformError) { - return new ExtendedSocketException(errorCode, platformError); + return new SocketException(errorCode, (uint)platformError); } } } diff --git a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.cs b/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.cs index b3e160c13d47ad..98cdd37b4e7ade 100644 --- a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.cs +++ b/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.cs @@ -7,29 +7,9 @@ namespace System.Net.Internals { internal static partial class SocketExceptionFactory { - private sealed class ExtendedSocketException : SocketException - { - private readonly EndPoint? _endPoint; - - public ExtendedSocketException(int errorCode, EndPoint? endPoint) - : base(errorCode) - { - _endPoint = endPoint; - } - - public ExtendedSocketException(SocketError socketError, int platformError) - : base((int)socketError) - { - HResult = platformError; - } - - public override string Message => - (_endPoint == null) ? base.Message : base.Message + " " + _endPoint.ToString(); - } - public static SocketException CreateSocketException(int socketError, EndPoint? endPoint) { - return new ExtendedSocketException(socketError, endPoint); + return new SocketException(socketError, endPoint?.ToString()); } } } diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs new file mode 100644 index 00000000000000..6a88e64440e606 --- /dev/null +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Net.Sockets; +using Xunit; + +namespace System.Net.Primitives.Functional.Tests +{ + public static class SocketExceptionTest + { + [Fact] + public static void Create_AllErrorCodes_Success() + { + foreach (SocketError error in Enum.GetValues(typeof(SocketError))) + { + SocketException e = new SocketException((int)error); + Assert.Equal(error, e.SocketErrorCode); + Assert.Null(e.InnerException); + Assert.NotNull(e.Message); + } + } + + [Fact] + public static void Create_ExceptionWithMessage_Success() + { + const string message = "Hello World"; + SocketException e = new SocketException((int)SocketError.AccessDenied, message); + Assert.Equal(SocketError.AccessDenied, e.SocketErrorCode); + Assert.Null(e.InnerException); + Assert.Equal(message, e.Message); + Assert.Contains(message, e.ToString()); + } + + [Fact] + public static void Create_SocketConnectException_Success() + { + using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 55555); + Assert.ThrowsAsync(() => socket.ConnectAsync(ep)); + try + { + socket.Connect(ep); + Assert.Fail("Socket Connect should throw SocketException in this case."); + } + catch(SocketException ex) + { + Assert.Equal(ep.ToString(), ex.Message); + } + } + } + } +} diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj b/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj index 4e2e897b0a6419..d31b916f781f33 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj @@ -25,7 +25,7 @@ - + + \ No newline at end of file From 6194440c85b9ffd58985c97dcf4ecb2d947823bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Fri, 2 Sep 2022 16:34:26 +0300 Subject: [PATCH 4/8] Update: Moving files from Internals to Sockets section in Common --- .../Internals/SocketExceptionFactory.Unix.cs | 15 ------------- .../SocketExceptionFactory.Windows.cs | 15 ------------- .../Sockets/SocketExceptionFactory.Unix.cs | 21 +++++++++++++++++++ .../SocketExceptionFactory.Windows.cs} | 7 +++---- .../Net/Sockets/SocketExceptionFactory.cs | 16 ++++++++++++++ .../FunctionalTests/SocketExceptionTest.cs | 3 ++- .../src/System.Net.Sockets.csproj | 8 +++++-- 7 files changed, 48 insertions(+), 37 deletions(-) delete mode 100644 src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs delete mode 100644 src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Windows.cs create mode 100644 src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs rename src/libraries/Common/src/System/Net/{Internals/SocketExceptionFactory.cs => Sockets/SocketExceptionFactory.Windows.cs} (63%) create mode 100644 src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs diff --git a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs b/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs deleted file mode 100644 index 945424a9edf6f9..00000000000000 --- a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Unix.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Net.Sockets; - -namespace System.Net.Internals -{ - internal static partial class SocketExceptionFactory - { - public static SocketException CreateSocketException(SocketError errorCode, int platformError) - { - return new SocketException(errorCode, (uint)platformError); - } - } -} diff --git a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Windows.cs b/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Windows.cs deleted file mode 100644 index 705157bcdd8b4b..00000000000000 --- a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.Windows.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Net.Sockets; - -namespace System.Net.Internals -{ - internal static partial class SocketExceptionFactory - { - public static SocketException CreateSocketException(SocketError errorCode, int platformError) - { - return new SocketException((int)errorCode); - } - } -} diff --git a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs new file mode 100644 index 00000000000000..61d760a42c03c4 --- /dev/null +++ b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Net.Sockets +{ + internal static partial class SocketExceptionFactory + { + public static SocketException CreateSocketException(int socketError, EndPoint? endPoint) + { + int nativeErr = (int)socketError; + + // If an interop error was not found, then don't invoke Info().RawErrno as that will fail with assert. + if (SocketErrorPal.TryGetNativeErrorForSocketError(error, out Interop.Error interopErr)) + { + nativeErr = interopErr.Info().RawErrno; + } + + return new SocketException(socketError, CreateMessage(nativeErr, endPoint)); + } + } +} diff --git a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.cs b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Windows.cs similarity index 63% rename from src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.cs rename to src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Windows.cs index 98cdd37b4e7ade..31c1a32421c980 100644 --- a/src/libraries/Common/src/System/Net/Internals/SocketExceptionFactory.cs +++ b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Windows.cs @@ -1,15 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Net.Sockets; - -namespace System.Net.Internals +namespace System.Net.Sockets { internal static partial class SocketExceptionFactory { public static SocketException CreateSocketException(int socketError, EndPoint? endPoint) { - return new SocketException(socketError, endPoint?.ToString()); + // Windows directly maps socketError to native error code. + return new SocketException(socketError, CreateMessage(socketError, endPoint)); } } } diff --git a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs new file mode 100644 index 00000000000000..ae2788057fc7c6 --- /dev/null +++ b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; + +namespace System.Net.Sockets +{ + internal static partial class SocketExceptionFactory + { + private static string CreateMessage(int nativeSocketError, EndPoint? endPoint) + { + string message = Marshal.GetPInvokeErrorMessage(nativeSocketError); + return endPoint == null ? message : message + " " + endPoint.ToString(); + } + } +} diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs index 6a88e64440e606..2ca5a869adfab9 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Sockets; +using System.Runtime.InteropServices; using Xunit; namespace System.Net.Primitives.Functional.Tests @@ -45,7 +46,7 @@ public static void Create_SocketConnectException_Success() } catch(SocketException ex) { - Assert.Equal(ep.ToString(), ex.Message); + Assert.Contains(Marshal.GetPInvokeErrorMessage(ex.NativeErrorCode) + " " + ep.ToString(), ex.Message); } } } diff --git a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj index 7f9c5ae276aa97..4b3af09ab75f95 100644 --- a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj +++ b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj @@ -78,8 +78,8 @@ Link="Common\System\Net\Internals\IPEndPointExtensions.cs" /> - + + @@ -278,6 +280,8 @@ Link="Common\Interop\Unix\System.Native\Interop.Pipe.cs" /> + From c0bd4baabb35b3fe59c6482ead0e864f93562328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Fri, 2 Sep 2022 18:26:55 +0300 Subject: [PATCH 5/8] Update: Review changes --- .../Sockets/SocketExceptionFactory.Unix.cs | 4 ++-- .../Sockets/SocketExceptionFactory.Windows.cs | 2 +- .../Net/Sockets/SocketExceptionFactory.cs | 5 ++-- .../FunctionalTests/SocketExceptionTest.cs | 20 ---------------- .../tests/FunctionalTests/Connect.cs | 23 +++++++++++++++++++ 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs index 61d760a42c03c4..632d3056e90676 100644 --- a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs +++ b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs @@ -5,12 +5,12 @@ namespace System.Net.Sockets { internal static partial class SocketExceptionFactory { - public static SocketException CreateSocketException(int socketError, EndPoint? endPoint) + public static SocketException CreateSocketException(int socketError, EndPoint endPoint) { int nativeErr = (int)socketError; // If an interop error was not found, then don't invoke Info().RawErrno as that will fail with assert. - if (SocketErrorPal.TryGetNativeErrorForSocketError(error, out Interop.Error interopErr)) + if (SocketErrorPal.TryGetNativeErrorForSocketError(socketError, out Interop.Error interopErr)) { nativeErr = interopErr.Info().RawErrno; } diff --git a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Windows.cs b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Windows.cs index 31c1a32421c980..ceb51ddf46fc34 100644 --- a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Windows.cs +++ b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Windows.cs @@ -5,7 +5,7 @@ namespace System.Net.Sockets { internal static partial class SocketExceptionFactory { - public static SocketException CreateSocketException(int socketError, EndPoint? endPoint) + public static SocketException CreateSocketException(int socketError, EndPoint endPoint) { // Windows directly maps socketError to native error code. return new SocketException(socketError, CreateMessage(socketError, endPoint)); diff --git a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs index ae2788057fc7c6..1c408e8c45b20b 100644 --- a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs +++ b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.cs @@ -7,10 +7,9 @@ namespace System.Net.Sockets { internal static partial class SocketExceptionFactory { - private static string CreateMessage(int nativeSocketError, EndPoint? endPoint) + private static string CreateMessage(int nativeSocketError, EndPoint endPoint) { - string message = Marshal.GetPInvokeErrorMessage(nativeSocketError); - return endPoint == null ? message : message + " " + endPoint.ToString(); + return Marshal.GetPInvokeErrorMessage(nativeSocketError) + " " + endPoint.ToString(); } } } diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs index 2ca5a869adfab9..3403548b948abd 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Sockets; -using System.Runtime.InteropServices; using Xunit; namespace System.Net.Primitives.Functional.Tests @@ -31,24 +30,5 @@ public static void Create_ExceptionWithMessage_Success() Assert.Equal(message, e.Message); Assert.Contains(message, e.ToString()); } - - [Fact] - public static void Create_SocketConnectException_Success() - { - using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 55555); - Assert.ThrowsAsync(() => socket.ConnectAsync(ep)); - try - { - socket.Connect(ep); - Assert.Fail("Socket Connect should throw SocketException in this case."); - } - catch(SocketException ex) - { - Assert.Contains(Marshal.GetPInvokeErrorMessage(ex.NativeErrorCode) + " " + ep.ToString(), ex.Message); - } - } - } } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs index f479d5d37ddccd..4acf0829c92f26 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using System.Runtime.InteropServices; using Xunit; using Xunit.Abstractions; using Xunit.Sdk; @@ -198,6 +199,28 @@ await RetryHelper.ExecuteAsync(async () => } }, maxAttempts: 10, retryWhen: e => e is XunitException); } + + [OuterLoop] + [Fact] + public static void Connect_ThrowSocketException_Success() + { + using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + int anonymousPort = socket.BindToAnonymousPort(IPAddress.Loopback); + IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, anonymousPort); + Assert.ThrowsAsync(() => socket.ConnectAsync(ep)); + try + { + socket.Connect(ep); + Assert.Fail("Socket Connect should throw SocketException in this case."); + } + catch (SocketException ex) + { + Assert.Contains(Marshal.GetPInvokeErrorMessage(ex.NativeErrorCode), ex.Message); + Assert.Contains(ep.ToString(), ex.Message); + } + } + } } public sealed class ConnectSync : Connect From 21edab2b0143472717ff7ed5351c631a29060504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Fri, 2 Sep 2022 19:10:46 +0300 Subject: [PATCH 6/8] Update: A little fix --- .../src/System/Net/Sockets/SocketExceptionFactory.Unix.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs index 632d3056e90676..ae503310856720 100644 --- a/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs +++ b/src/libraries/Common/src/System/Net/Sockets/SocketExceptionFactory.Unix.cs @@ -10,7 +10,7 @@ public static SocketException CreateSocketException(int socketError, EndPoint en int nativeErr = (int)socketError; // If an interop error was not found, then don't invoke Info().RawErrno as that will fail with assert. - if (SocketErrorPal.TryGetNativeErrorForSocketError(socketError, out Interop.Error interopErr)) + if (SocketErrorPal.TryGetNativeErrorForSocketError((SocketError)socketError, out Interop.Error interopErr)) { nativeErr = interopErr.Info().RawErrno; } From 3617875403263433b107f16eab4f9f5433a169ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Mon, 5 Sep 2022 21:11:47 +0300 Subject: [PATCH 7/8] Update: Move test into async section --- .../tests/FunctionalTests/Connect.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs index 4acf0829c92f26..7f9fb007e74e7b 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs @@ -199,6 +199,26 @@ await RetryHelper.ExecuteAsync(async () => } }, maxAttempts: 10, retryWhen: e => e is XunitException); } + } + + public sealed class ConnectSync : Connect + { + public ConnectSync(ITestOutputHelper output) : base(output) {} + } + + public sealed class ConnectSyncForceNonBlocking : Connect + { + public ConnectSyncForceNonBlocking(ITestOutputHelper output) : base(output) {} + } + + public sealed class ConnectApm : Connect + { + public ConnectApm(ITestOutputHelper output) : base(output) {} + } + + public sealed class ConnectTask : Connect + { + public ConnectTask(ITestOutputHelper output) : base(output) {} [OuterLoop] [Fact] @@ -223,26 +243,6 @@ public static void Connect_ThrowSocketException_Success() } } - public sealed class ConnectSync : Connect - { - public ConnectSync(ITestOutputHelper output) : base(output) {} - } - - public sealed class ConnectSyncForceNonBlocking : Connect - { - public ConnectSyncForceNonBlocking(ITestOutputHelper output) : base(output) {} - } - - public sealed class ConnectApm : Connect - { - public ConnectApm(ITestOutputHelper output) : base(output) {} - } - - public sealed class ConnectTask : Connect - { - public ConnectTask(ITestOutputHelper output) : base(output) {} - } - public sealed class ConnectEap : Connect { public ConnectEap(ITestOutputHelper output) : base(output) {} From 2e4924ea613a3b42e3606391c630211a99b58cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C4=B0brahim=20AKSOY?= Date: Tue, 6 Sep 2022 17:42:40 +0300 Subject: [PATCH 8/8] Update: Review changes --- .../tests/FunctionalTests/SocketExceptionTest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs index 3403548b948abd..920df922cf0d65 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketExceptionTest.cs @@ -23,12 +23,12 @@ public static void Create_AllErrorCodes_Success() [Fact] public static void Create_ExceptionWithMessage_Success() { - const string message = "Hello World"; - SocketException e = new SocketException((int)SocketError.AccessDenied, message); + const string Message = "Hello World"; + SocketException e = new SocketException((int)SocketError.AccessDenied, Message); Assert.Equal(SocketError.AccessDenied, e.SocketErrorCode); Assert.Null(e.InnerException); - Assert.Equal(message, e.Message); - Assert.Contains(message, e.ToString()); + Assert.Equal(Message, e.Message); + Assert.Contains(Message, e.ToString()); } } }