Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update: Moving files from Internals to Sockets section in Common
  • Loading branch information
liveans committed Sep 2, 2022
commit 6194440c85b9ffd58985c97dcf4ecb2d947823bc

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
Link="Common\System\Net\Internals\IPEndPointExtensions.cs" />
<Compile Include="$(CommonPath)System\Net\Internals\IPAddressExtensions.cs"
Link="Common\System\Net\Internals\IPAddressExtensions.cs" />
<Compile Include="$(CommonPath)System\Net\Internals\SocketExceptionFactory.cs"
Link="Common\System\Net\Internals\SocketExceptionFactory.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketExceptionFactory.cs"
Link="Common\System\Net\Sockets\SocketExceptionFactory.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\ProtocolFamily.cs"
Link="Common\System\Net\Sockets\ProtocolFamily.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\ProtocolType.cs"
Expand All @@ -100,6 +100,8 @@
Link="Common\System\Net\SocketAddressPal.Windows.cs" />
<Compile Include="$(CommonPath)System\Net\SocketProtocolSupportPal.Windows.cs"
Link="Common\System\Net\SocketProtocolSupportPal.Windows" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketExceptionFactory.Windows.cs"
Link="Common\System\Net\Sockets\SocketExceptionFactory.Windows.cs" />
<!-- Interop -->
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
Expand Down Expand Up @@ -278,6 +280,8 @@
Link="Common\Interop\Unix\System.Native\Interop.Pipe.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Write.cs"
Link="Common\Interop\Unix\System.Native\Interop.Write.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketExceptionFactory.Unix.cs"
Link="Common\System\Net\Sockets\SocketExceptionFactory.Unix.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives" />
Expand Down