1065 references to SocketError
aspire (3)
Backchannel\AuxiliaryBackchannelMonitor.cs (2)
530
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.ConnectionRefused)
712
/// A connect that fails with <see cref="
SocketError
.ConnectionRefused"/> cannot distinguish an
src\Shared\SocketExceptionHelpers.cs (1)
18
return exception is IOException { InnerException: SocketException { SocketErrorCode:
SocketError
.ConnectionReset } };
aspire-managed (1)
TerminalHostForwarder.cs (1)
153
catch (IOException ex) when (ex.InnerException is SocketException { SocketErrorCode:
SocketError
.ConnectionReset })
Aspire.Cli.Tests (9)
Backchannel\AuxiliaryBackchannelMonitorTests.cs (1)
464
ConnectAsyncCallback = _ => ValueTask.FromException<Socket>(new SocketException((int)
SocketError
.ConnectionRefused))
Commands\RunCommandTests.cs (1)
2415
new SocketException((int)
SocketError
.ConnectionRefused)));
Commands\TelemetryFollowTests.cs (1)
34
? new IOException("Connection reset.", new SocketException((int)
SocketError
.ConnectionReset))
DotNet\DotNetCliRunnerTests.cs (4)
1748
ConnectAsyncCallback = (_, _) => throw new SocketException((int)
SocketError
.ConnectionRefused)
1788
ConnectAsyncCallback = (_, _) => throw new SocketException((int)
SocketError
.ConnectionRefused)
1828
ConnectAsyncCallback = (_, _) => throw new SocketException((int)
SocketError
.ConnectionRefused)
1870
ConnectAsyncCallback = (_, _) => throw new SocketException((int)
SocketError
.ConnectionRefused)
Projects\GuestAppHostProjectTests.cs (2)
1996
ConnectAsyncCallback = (_, _) => throw new SocketException((int)
SocketError
.ConnectionRefused)
2024
ConnectAsyncCallback = (_, _) => throw new SocketException((int)
SocketError
.ConnectionRefused)
Aspire.Dashboard (1)
DashboardWebApplication.cs (1)
1242
if (current is SocketException { SocketErrorCode:
SocketError
.AddressAlreadyInUse })
Aspire.Dashboard.Tests (1)
Integration\ServerRetryHelper.cs (1)
171
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.AddressAlreadyInUse)
Aspire.Hosting (1)
src\Shared\SocketExceptionHelpers.cs (1)
18
return exception is IOException { InnerException: SocketException { SocketErrorCode:
SocketError
.ConnectionReset } };
Aspire.Hosting.Native.Core.Tests (1)
NativeSocketIsolationTests.cs (1)
219
throw new SocketException((int)
SocketError
.ConnectionReset);
Aspire.Hosting.Native.Server (2)
Dashboard\DcpDashboard.cs (1)
88
SocketException { SocketErrorCode:
SocketError
.ConnectionRefused })
src\Shared\DcpConnectionMaterial.cs (1)
141
InnerException: SocketException { SocketErrorCode:
SocketError
.ConnectionRefused } or AuthenticationException
Aspire.Hosting.Tests (8)
Utils\SocketExceptionHelpersTests.cs (8)
13
[InlineData(
SocketError
.ConnectionReset, true)]
14
[InlineData(
SocketError
.ConnectionAborted, false)]
15
[InlineData(
SocketError
.ConnectionRefused, false)]
16
[InlineData(
SocketError
.NetworkReset, false)]
17
[InlineData(
SocketError
.Shutdown, false)]
18
[InlineData(
SocketError
.TimedOut, false)]
19
public void IsConnectionReset_OnlyMatchesResetSocketError(
SocketError
socketError, bool expected)
29
var socketException = new SocketException((int)
SocketError
.ConnectionReset);
Aspire.TerminalHost (4)
TerminalHostControlListener.cs (4)
324
private static bool IsTransientAcceptError(
SocketError
code) => code switch
328
SocketError
.TryAgain => true,
329
SocketError
.WouldBlock => true,
331
SocketError
.Interrupted => true,
dotnet-svcutil-lib (2)
FrameworkFork\System.ServiceModel\System\ServiceModel\Channels\CoreClrSocketConnection.cs (2)
481
if (_asyncWriteEventArgs.SocketError ==
SocketError
.Success)
720
if (_asyncReadEventArgs.SocketError ==
SocketError
.Success)
Infrastructure.Tests (1)
PowerShellScripts\DownloadNativeArchivesTests.cs (1)
39
Assert.Equal(
SocketError
.AddressAlreadyInUse, ex.SocketErrorCode);
Microsoft.AspNetCore.Server.Kestrel.Transport.Quic (1)
Internal\QuicConnectionListener.cs (1)
134
catch (SocketException e) when (e.SocketErrorCode ==
SocketError
.AddressAlreadyInUse)
Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets (21)
Internal\SocketAwaitableEventArgs.cs (3)
51
if (SocketError !=
SocketError
.Success)
59
protected static SocketException CreateException(
SocketError
e)
67
SocketError ==
SocketError
.Success ? ValueTaskSourceStatus.Succeeded :
Internal\SocketConnection.cs (8)
426
private static bool IsConnectionResetError(
SocketError
errorCode)
428
return errorCode ==
SocketError
.ConnectionReset ||
429
errorCode ==
SocketError
.Shutdown ||
430
(errorCode ==
SocketError
.ConnectionAborted && OperatingSystem.IsWindows());
433
private static bool IsConnectionAbortError(
SocketError
errorCode)
436
return errorCode ==
SocketError
.OperationAborted ||
437
errorCode ==
SocketError
.Interrupted ||
438
(errorCode ==
SocketError
.InvalidArgument && !OperatingSystem.IsWindows());
Internal\SocketReceiver.cs (4)
25
var
error = SocketError;
27
return error ==
SocketError
.Success
42
var
error = SocketError;
44
return error ==
SocketError
.Success
Internal\SocketSender.cs (4)
35
var
error = SocketError;
37
return error ==
SocketError
.Success
69
var
error = SocketError;
71
return error ==
SocketError
.Success
SocketConnectionListener.cs (2)
46
catch (SocketException e) when (e.SocketErrorCode ==
SocketError
.AddressAlreadyInUse)
82
catch (SocketException e) when (e.SocketErrorCode ==
SocketError
.OperationAborted)
Microsoft.Extensions.Diagnostics.ExceptionSummarization (4)
HttpExceptionSummaryProvider.cs (4)
25
private static readonly FrozenDictionary<
SocketError
, int> _socketErrorMap;
37
var socketErrors = new Dictionary<
SocketError
, int>();
39
foreach (
var
socketError in Enum.GetValues<
SocketError
>())
Microsoft.Extensions.Diagnostics.ExceptionSummarization.Tests (5)
ExceptionSummarizerTests.cs (3)
22
.Concat(Enum.GetNames(typeof(
SocketError
)).ToList()).ToList();
185
var exception = new Exception("test", new SocketException((int)
SocketError
.TimedOut));
186
var descriptionIndex = _httpDescriptions.FindIndex(x => x.Equals(
SocketError
.TimedOut.ToString()));
HttpExceptionSummaryProviderTests.cs (2)
22
foreach (var socketError in Enum.GetValues(typeof(
SocketError
)))
92
public void Describe_WithKnownSocketException_ReturnDetails(
SocketError
socketError)
Microsoft.Extensions.Diagnostics.Probes.Tests (1)
TcpEndpointProbesServiceTests.cs (1)
109
if (e.SocketErrorCode ==
SocketError
.ConnectionRefused)
Microsoft.NET.Build.Containers (3)
AuthRealmHandlerFactory.cs (3)
163
HttpRequestError error = ex.SocketErrorCode is
SocketError
.HostNotFound or
SocketError
.NoData or
SocketError
.TryAgain
Microsoft.TestPlatform.CommunicationUtilities (2)
SocketCommunicationManager.cs (1)
380
&& socketException.SocketErrorCode ==
SocketError
.TimedOut)
TcpClientExtensions.cs (1)
73
&& socketException.SocketErrorCode ==
SocketError
.TimedOut)
netstandard (1)
netstandard.cs (1)
1271
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Net.Sockets.
SocketError
))]
System (1)
parent\ref\System.cs (1)
761
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Net.Sockets.
SocketError
))]
System.IO.Pipes (4)
System\IO\Pipes\NamedPipeClientStream.Unix.cs (3)
67
case
SocketError
.AddressAlreadyInUse:
68
case
SocketError
.AddressNotAvailable:
69
case
SocketError
.ConnectionRefused:
System\IO\Pipes\PipeStream.Unix.cs (1)
334
if (e.SocketErrorCode ==
SocketError
.Shutdown) // EPIPE
System.Net (1)
System.Net.cs (1)
42
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Net.Sockets.
SocketError
))]
System.Net.Http (2)
System\Net\Http\SocketsHttpHandler\ConnectHelper.cs (2)
157
socketException.SocketErrorCode is
SocketError
.HostNotFound or
SocketError
.TryAgain)
System.Net.HttpListener (2)
System\Net\Managed\HttpEndPointListener.cs (1)
110
Socket? accepted = args.SocketError ==
SocketError
.Success ? args.AcceptSocket : null;
System\Net\Managed\ListenerAsyncResult.Managed.cs (1)
71
_exception = new HttpListenerException((int)
SocketError
.OperationAborted, SR.net_listener_close);
System.Net.NameResolution (29)
System\Net\Dns.cs (10)
479
exception = new SocketException((int)
SocketError
.HostNotFound);
511
SocketError
errorCode = NameResolutionPal.TryGetAddrInfo(hostName, justAddresses, addressFamily, out string? newHostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode);
513
if (errorCode !=
SocketError
.Success)
560
catch (SocketException ex) when (addressFamily == AddressFamily.InterNetworkV6 && ex.SocketErrorCode ==
SocketError
.HostNotFound)
593
SocketError
errorCode;
598
if (errorCode !=
SocketError
.Success)
626
if (errorCode !=
SocketError
.Success)
857
catch (SocketException ex) when (family == AddressFamily.InterNetworkV6 && ex.SocketErrorCode ==
SocketError
.HostNotFound)
870
catch (SocketException ex) when (family == AddressFamily.InterNetworkV6 && ex.SocketErrorCode ==
SocketError
.HostNotFound)
989
private static SocketException CreateException(
SocketError
error, int nativeError) =>
System\Net\DnsResolverPal.Managed.cs (1)
519
lastException = ex.SocketErrorCode ==
SocketError
.TimedOut
System\Net\DnsSocket.cs (1)
114
throw new SocketException((int)
SocketError
.TimedOut);
System\Net\NameResolutionPal.Unix.cs (13)
28
private static
SocketError
GetSocketErrorForNativeError(int error)
33
return
SocketError
.Success;
35
return
SocketError
.TryAgain;
38
return
SocketError
.InvalidArgument;
40
return
SocketError
.NoRecovery;
42
return
SocketError
.AddressFamilyNotSupported;
44
return
SocketError
.HostNotFound;
49
return
SocketError
.SocketError;
52
return
SocketError
.SocketError;
131
public static unsafe
SocketError
TryGetAddrInfo(string name, bool justAddresses, AddressFamily addressFamily, out string? hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode)
152
return
SocketError
.Success;
155
public static unsafe string? TryGetNameInfo(IPAddress addr, out
SocketError
socketError, out int nativeErrorCode)
190
return socketError ==
SocketError
.Success ? Utf8StringMarshaller.ConvertToManaged(buffer) : null;
System\Net\NameResolutionTelemetry.cs (4)
147
SocketError
.HostNotFound => "host_not_found",
148
SocketError
.TryAgain => "try_again",
149
SocketError
.AddressFamilyNotSupported => "address_family_not_supported",
150
SocketError
.NoRecovery => "no_recovery",
System.Net.NetworkInformation (2)
src\runtime\src\libraries\Common\src\System\Net\NetworkInformation\NetworkInformationException.cs (1)
44
internal NetworkInformationException(
SocketError
socketError) : base((int)socketError)
System\Net\NetworkInformation\NetworkAddressChange.Unix.cs (1)
230
catch (SocketException se) when (se.SocketErrorCode ==
SocketError
.OperationAborted)
System.Net.Ping (101)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\LibraryImports.g.cs (3)
31
internal static unsafe partial global::System.Net.Sockets.
SocketError
ReceiveSocketError(global::System.Runtime.InteropServices.SafeHandle socket, global::Interop.Sys.MessageHeader* messageHeader)
36
global::System.Net.Sockets.
SocketError
__retVal = default;
57
static extern unsafe global::System.Net.Sockets.
SocketError
__PInvoke(nint __socket_native, global::Interop.Sys.MessageHeader* __messageHeader_native);
src\runtime\src\libraries\Common\src\Interop\Unix\System.Native\Interop.ReceiveSocketError.cs (1)
13
internal static unsafe partial
SocketError
ReceiveSocketError(SafeHandle socket, MessageHeader* messageHeader);
src\runtime\src\libraries\Common\src\System\Net\IPEndPointExtensions.cs (1)
29
throw new SocketException((int)
SocketError
.AddressFamilyNotSupported);
src\runtime\src\libraries\Common\src\System\Net\Sockets\SocketErrorPal.Unix.cs (88)
20
internal static
SocketError
GetSocketErrorForNativeError(Interop.Error errno) => errno switch
22
Interop.Error.EACCES =>
SocketError
.AccessDenied,
23
Interop.Error.EADDRINUSE =>
SocketError
.AddressAlreadyInUse,
24
Interop.Error.EADDRNOTAVAIL =>
SocketError
.AddressNotAvailable,
25
Interop.Error.EAFNOSUPPORT =>
SocketError
.AddressFamilyNotSupported,
26
Interop.Error.EAGAIN =>
SocketError
.WouldBlock,
27
Interop.Error.EALREADY =>
SocketError
.AlreadyInProgress,
28
Interop.Error.EBADF =>
SocketError
.OperationAborted,
29
Interop.Error.ECANCELED =>
SocketError
.OperationAborted,
30
Interop.Error.ECONNABORTED =>
SocketError
.ConnectionAborted,
31
Interop.Error.ECONNREFUSED =>
SocketError
.ConnectionRefused,
32
Interop.Error.ECONNRESET =>
SocketError
.ConnectionReset,
33
Interop.Error.EDESTADDRREQ =>
SocketError
.DestinationAddressRequired,
34
Interop.Error.EFAULT =>
SocketError
.Fault,
35
Interop.Error.EHOSTDOWN =>
SocketError
.HostDown,
36
Interop.Error.ENXIO =>
SocketError
.HostNotFound, // not perfect, but closest match available
37
Interop.Error.EHOSTUNREACH =>
SocketError
.HostUnreachable,
38
Interop.Error.EINPROGRESS =>
SocketError
.InProgress,
39
Interop.Error.EINTR =>
SocketError
.Interrupted,
40
Interop.Error.EINVAL =>
SocketError
.InvalidArgument,
41
Interop.Error.EISCONN =>
SocketError
.IsConnected,
42
Interop.Error.EMFILE =>
SocketError
.TooManyOpenSockets,
43
Interop.Error.EMSGSIZE =>
SocketError
.MessageSize,
44
Interop.Error.ENETDOWN =>
SocketError
.NetworkDown,
45
Interop.Error.ENETRESET =>
SocketError
.NetworkReset,
46
Interop.Error.ENETUNREACH =>
SocketError
.NetworkUnreachable,
47
Interop.Error.ENFILE =>
SocketError
.TooManyOpenSockets,
48
Interop.Error.ENOBUFS =>
SocketError
.NoBufferSpaceAvailable,
49
Interop.Error.ENODATA =>
SocketError
.NoData,
50
Interop.Error.ENOENT =>
SocketError
.AddressNotAvailable,
51
Interop.Error.ENOPROTOOPT =>
SocketError
.ProtocolOption,
52
Interop.Error.ENOTCONN =>
SocketError
.NotConnected,
53
Interop.Error.ENOTSOCK =>
SocketError
.NotSocket,
54
Interop.Error.ENOTSUP =>
SocketError
.OperationNotSupported,
55
Interop.Error.EPERM =>
SocketError
.AccessDenied,
56
Interop.Error.EPIPE =>
SocketError
.Shutdown,
57
Interop.Error.EPFNOSUPPORT =>
SocketError
.ProtocolFamilyNotSupported,
58
Interop.Error.EPROTONOSUPPORT =>
SocketError
.ProtocolNotSupported,
59
Interop.Error.EPROTOTYPE =>
SocketError
.ProtocolType,
60
Interop.Error.ESOCKTNOSUPPORT =>
SocketError
.SocketNotSupported,
61
Interop.Error.ESHUTDOWN =>
SocketError
.Disconnecting,
62
Interop.Error.SUCCESS =>
SocketError
.Success,
63
Interop.Error.ETIMEDOUT =>
SocketError
.TimedOut,
64
_ =>
SocketError
.SocketError, // unknown native error, just treat it as a generic SocketError
67
private static Interop.Error GetNativeErrorForSocketErrorHelper(
SocketError
error) => error switch
75
SocketError
.AccessDenied => Interop.Error.EACCES, // could also have been EPERM
76
SocketError
.AddressAlreadyInUse => Interop.Error.EADDRINUSE,
77
SocketError
.AddressNotAvailable => Interop.Error.EADDRNOTAVAIL,
78
SocketError
.AddressFamilyNotSupported => Interop.Error.EAFNOSUPPORT,
79
SocketError
.AlreadyInProgress => Interop.Error.EALREADY,
80
SocketError
.ConnectionAborted => Interop.Error.ECONNABORTED,
81
SocketError
.ConnectionRefused => Interop.Error.ECONNREFUSED,
82
SocketError
.ConnectionReset => Interop.Error.ECONNRESET,
83
SocketError
.DestinationAddressRequired => Interop.Error.EDESTADDRREQ,
84
SocketError
.Disconnecting => Interop.Error.ESHUTDOWN,
85
SocketError
.Fault => Interop.Error.EFAULT,
86
SocketError
.HostDown => Interop.Error.EHOSTDOWN,
87
SocketError
.HostNotFound => Interop.Error.EHOSTNOTFOUND,
88
SocketError
.HostUnreachable => Interop.Error.EHOSTUNREACH,
89
SocketError
.InProgress => Interop.Error.EINPROGRESS,
90
SocketError
.Interrupted => Interop.Error.EINTR,
91
SocketError
.InvalidArgument => Interop.Error.EINVAL,
92
SocketError
.IOPending => Interop.Error.EINPROGRESS,
93
SocketError
.IsConnected => Interop.Error.EISCONN,
94
SocketError
.MessageSize => Interop.Error.EMSGSIZE,
95
SocketError
.NetworkDown => Interop.Error.ENETDOWN,
96
SocketError
.NetworkReset => Interop.Error.ENETRESET,
97
SocketError
.NetworkUnreachable => Interop.Error.ENETUNREACH,
98
SocketError
.NoBufferSpaceAvailable => Interop.Error.ENOBUFS,
99
SocketError
.NoData => Interop.Error.ENODATA,
100
SocketError
.NotConnected => Interop.Error.ENOTCONN,
101
SocketError
.NotSocket => Interop.Error.ENOTSOCK,
102
SocketError
.OperationAborted => Interop.Error.ECANCELED,
103
SocketError
.OperationNotSupported => Interop.Error.ENOTSUP,
104
SocketError
.ProtocolFamilyNotSupported => Interop.Error.EPFNOSUPPORT,
105
SocketError
.ProtocolNotSupported => Interop.Error.EPROTONOSUPPORT,
106
SocketError
.ProtocolOption => Interop.Error.ENOPROTOOPT,
107
SocketError
.ProtocolType => Interop.Error.EPROTOTYPE,
108
SocketError
.Shutdown => Interop.Error.EPIPE,
109
SocketError
.SocketNotSupported => Interop.Error.ESOCKTNOSUPPORT,
110
SocketError
.Success => Interop.Error.SUCCESS,
111
SocketError
.TimedOut => Interop.Error.ETIMEDOUT,
112
SocketError
.TooManyOpenSockets => Interop.Error.ENFILE, // could also have been EMFILE
113
SocketError
.TryAgain => Interop.Error.EAGAIN, // not a perfect mapping, but better than nothing
114
SocketError
.WouldBlock => Interop.Error.EAGAIN,
115
SocketError
.SocketError => Interop.Error.ESOCKETERROR,
119
internal static Interop.Error GetNativeErrorForSocketError(
SocketError
error)
130
internal static bool TryGetNativeErrorForSocketError(
SocketError
error, out Interop.Error errno)
System\Net\NetworkInformation\Ping.RawSocket.cs (8)
278
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.TimedOut)
281
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.MessageSize)
285
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.HostUnreachable)
304
SocketError
result;
311
if (result ==
SocketError
.Success && header.SocketAddressLen > 0)
363
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.TimedOut)
366
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.MessageSize)
373
catch (SocketException ex) when (ex.SocketErrorCode ==
SocketError
.HostUnreachable)
System.Net.Primitives (100)
src\runtime\src\libraries\Common\src\System\Net\IPEndPointExtensions.cs (1)
29
throw new SocketException((int)
SocketError
.AddressFamilyNotSupported);
src\runtime\src\libraries\Common\src\System\Net\Sockets\SocketErrorPal.Unix.cs (88)
20
internal static
SocketError
GetSocketErrorForNativeError(Interop.Error errno) => errno switch
22
Interop.Error.EACCES =>
SocketError
.AccessDenied,
23
Interop.Error.EADDRINUSE =>
SocketError
.AddressAlreadyInUse,
24
Interop.Error.EADDRNOTAVAIL =>
SocketError
.AddressNotAvailable,
25
Interop.Error.EAFNOSUPPORT =>
SocketError
.AddressFamilyNotSupported,
26
Interop.Error.EAGAIN =>
SocketError
.WouldBlock,
27
Interop.Error.EALREADY =>
SocketError
.AlreadyInProgress,
28
Interop.Error.EBADF =>
SocketError
.OperationAborted,
29
Interop.Error.ECANCELED =>
SocketError
.OperationAborted,
30
Interop.Error.ECONNABORTED =>
SocketError
.ConnectionAborted,
31
Interop.Error.ECONNREFUSED =>
SocketError
.ConnectionRefused,
32
Interop.Error.ECONNRESET =>
SocketError
.ConnectionReset,
33
Interop.Error.EDESTADDRREQ =>
SocketError
.DestinationAddressRequired,
34
Interop.Error.EFAULT =>
SocketError
.Fault,
35
Interop.Error.EHOSTDOWN =>
SocketError
.HostDown,
36
Interop.Error.ENXIO =>
SocketError
.HostNotFound, // not perfect, but closest match available
37
Interop.Error.EHOSTUNREACH =>
SocketError
.HostUnreachable,
38
Interop.Error.EINPROGRESS =>
SocketError
.InProgress,
39
Interop.Error.EINTR =>
SocketError
.Interrupted,
40
Interop.Error.EINVAL =>
SocketError
.InvalidArgument,
41
Interop.Error.EISCONN =>
SocketError
.IsConnected,
42
Interop.Error.EMFILE =>
SocketError
.TooManyOpenSockets,
43
Interop.Error.EMSGSIZE =>
SocketError
.MessageSize,
44
Interop.Error.ENETDOWN =>
SocketError
.NetworkDown,
45
Interop.Error.ENETRESET =>
SocketError
.NetworkReset,
46
Interop.Error.ENETUNREACH =>
SocketError
.NetworkUnreachable,
47
Interop.Error.ENFILE =>
SocketError
.TooManyOpenSockets,
48
Interop.Error.ENOBUFS =>
SocketError
.NoBufferSpaceAvailable,
49
Interop.Error.ENODATA =>
SocketError
.NoData,
50
Interop.Error.ENOENT =>
SocketError
.AddressNotAvailable,
51
Interop.Error.ENOPROTOOPT =>
SocketError
.ProtocolOption,
52
Interop.Error.ENOTCONN =>
SocketError
.NotConnected,
53
Interop.Error.ENOTSOCK =>
SocketError
.NotSocket,
54
Interop.Error.ENOTSUP =>
SocketError
.OperationNotSupported,
55
Interop.Error.EPERM =>
SocketError
.AccessDenied,
56
Interop.Error.EPIPE =>
SocketError
.Shutdown,
57
Interop.Error.EPFNOSUPPORT =>
SocketError
.ProtocolFamilyNotSupported,
58
Interop.Error.EPROTONOSUPPORT =>
SocketError
.ProtocolNotSupported,
59
Interop.Error.EPROTOTYPE =>
SocketError
.ProtocolType,
60
Interop.Error.ESOCKTNOSUPPORT =>
SocketError
.SocketNotSupported,
61
Interop.Error.ESHUTDOWN =>
SocketError
.Disconnecting,
62
Interop.Error.SUCCESS =>
SocketError
.Success,
63
Interop.Error.ETIMEDOUT =>
SocketError
.TimedOut,
64
_ =>
SocketError
.SocketError, // unknown native error, just treat it as a generic SocketError
67
private static Interop.Error GetNativeErrorForSocketErrorHelper(
SocketError
error) => error switch
75
SocketError
.AccessDenied => Interop.Error.EACCES, // could also have been EPERM
76
SocketError
.AddressAlreadyInUse => Interop.Error.EADDRINUSE,
77
SocketError
.AddressNotAvailable => Interop.Error.EADDRNOTAVAIL,
78
SocketError
.AddressFamilyNotSupported => Interop.Error.EAFNOSUPPORT,
79
SocketError
.AlreadyInProgress => Interop.Error.EALREADY,
80
SocketError
.ConnectionAborted => Interop.Error.ECONNABORTED,
81
SocketError
.ConnectionRefused => Interop.Error.ECONNREFUSED,
82
SocketError
.ConnectionReset => Interop.Error.ECONNRESET,
83
SocketError
.DestinationAddressRequired => Interop.Error.EDESTADDRREQ,
84
SocketError
.Disconnecting => Interop.Error.ESHUTDOWN,
85
SocketError
.Fault => Interop.Error.EFAULT,
86
SocketError
.HostDown => Interop.Error.EHOSTDOWN,
87
SocketError
.HostNotFound => Interop.Error.EHOSTNOTFOUND,
88
SocketError
.HostUnreachable => Interop.Error.EHOSTUNREACH,
89
SocketError
.InProgress => Interop.Error.EINPROGRESS,
90
SocketError
.Interrupted => Interop.Error.EINTR,
91
SocketError
.InvalidArgument => Interop.Error.EINVAL,
92
SocketError
.IOPending => Interop.Error.EINPROGRESS,
93
SocketError
.IsConnected => Interop.Error.EISCONN,
94
SocketError
.MessageSize => Interop.Error.EMSGSIZE,
95
SocketError
.NetworkDown => Interop.Error.ENETDOWN,
96
SocketError
.NetworkReset => Interop.Error.ENETRESET,
97
SocketError
.NetworkUnreachable => Interop.Error.ENETUNREACH,
98
SocketError
.NoBufferSpaceAvailable => Interop.Error.ENOBUFS,
99
SocketError
.NoData => Interop.Error.ENODATA,
100
SocketError
.NotConnected => Interop.Error.ENOTCONN,
101
SocketError
.NotSocket => Interop.Error.ENOTSOCK,
102
SocketError
.OperationAborted => Interop.Error.ECANCELED,
103
SocketError
.OperationNotSupported => Interop.Error.ENOTSUP,
104
SocketError
.ProtocolFamilyNotSupported => Interop.Error.EPFNOSUPPORT,
105
SocketError
.ProtocolNotSupported => Interop.Error.EPROTONOSUPPORT,
106
SocketError
.ProtocolOption => Interop.Error.ENOPROTOOPT,
107
SocketError
.ProtocolType => Interop.Error.EPROTOTYPE,
108
SocketError
.Shutdown => Interop.Error.EPIPE,
109
SocketError
.SocketNotSupported => Interop.Error.ESOCKTNOSUPPORT,
110
SocketError
.Success => Interop.Error.SUCCESS,
111
SocketError
.TimedOut => Interop.Error.ETIMEDOUT,
112
SocketError
.TooManyOpenSockets => Interop.Error.ENFILE, // could also have been EMFILE
113
SocketError
.TryAgain => Interop.Error.EAGAIN, // not a perfect mapping, but better than nothing
114
SocketError
.WouldBlock => Interop.Error.EAGAIN,
115
SocketError
.SocketError => Interop.Error.ESOCKETERROR,
119
internal static Interop.Error GetNativeErrorForSocketError(
SocketError
error)
130
internal static bool TryGetNativeErrorForSocketError(
SocketError
error, out Interop.Error errno)
System\Net\IPAddress.cs (2)
773
private void ThrowSocketOperationNotSupported() => throw new SocketException(
SocketError
.OperationNotSupported, SR.Format(SR.net_SocketException_OperationNotSupported, AddressFamily));
776
private static void ThrowSocketOperationNotSupportedReadOnly() => throw new SocketException(
SocketError
.OperationNotSupported, SR.net_SocketException_OperationNotSupported_ReadOnlyIPAddress);
System\Net\IPAddressParser.cs (1)
59
throw new FormatException(SR.dns_bad_ip_address, new SocketException(
SocketError
.InvalidArgument));
System\Net\SocketException.cs (6)
16
private readonly
SocketError
_errorCode;
19
public SocketException(int errorCode) : this((
SocketError
)errorCode)
34
public SocketException(int errorCode, string? message) : this((
SocketError
)errorCode, message)
39
internal SocketException(
SocketError
socketError) : base(GetNativeErrorForSocketError(socketError))
45
internal SocketException(
SocketError
socketError, string? message) : base(GetNativeErrorForSocketError(socketError), message)
52
public
SocketError
SocketErrorCode => _errorCode;
System\Net\SocketException.Unix.cs (2)
15
internal SocketException(
SocketError
errorCode, uint platformError) : base((int)platformError)
24
private static int GetNativeErrorForSocketError(
SocketError
error)
System.Net.Quic (6)
src\runtime\src\libraries\Common\src\System\Net\IPEndPointExtensions.cs (1)
29
throw new SocketException((int)
SocketError
.AddressFamilyNotSupported);
System\Net\Quic\Internal\ThrowHelper.cs (4)
83
if (status == QUIC_STATUS_INVALID_ADDRESS) return new SocketException((int)
SocketError
.AddressNotAvailable);
84
if (status == QUIC_STATUS_ADDRESS_IN_USE) return new SocketException((int)
SocketError
.AddressAlreadyInUse);
85
if (status == QUIC_STATUS_UNREACHABLE) return new SocketException((int)
SocketError
.HostUnreachable);
86
if (status == QUIC_STATUS_ADDRESS_NOT_AVAILABLE) return new SocketException((int)
SocketError
.AddressFamilyNotSupported);
System\Net\Quic\QuicConnection.cs (1)
401
throw new SocketException((int)
SocketError
.HostNotFound);
System.Net.Requests (4)
System\Net\FtpWebRequest.cs (2)
920
sEx.SocketErrorCode ==
SocketError
.TimedOut)
939
if (se.SocketErrorCode ==
SocketError
.HostNotFound)
System\Net\WebException.cs (2)
115
case
SocketError
.NoData:
116
case
SocketError
.HostNotFound:
System.Net.Security (20)
System\Net\Security\TlsOperationStatus.cs (1)
24
/// <see cref="System.Net.Sockets.
SocketError
.WouldBlock"/> mid-write; retry the
System\Net\Security\TlsSession.cs (19)
2073
private bool TryDrainPendingToSocket(out
SocketError
lastError)
2075
lastError =
SocketError
.Success;
2081
out
SocketError
err);
2129
if (!TryDrainPendingToSocket(out
SocketError
drainErr))
2131
if (drainErr ==
SocketError
.WouldBlock)
2158
out
SocketError
sendErr);
2164
if (sendErr ==
SocketError
.WouldBlock)
2185
out
SocketError
recvErr);
2191
if (recvErr ==
SocketError
.WouldBlock)
2282
out
SocketError
recvErr);
2288
if (recvErr ==
SocketError
.WouldBlock)
2324
if (!TryDrainPendingToSocket(out
SocketError
drainErr))
2326
if (drainErr ==
SocketError
.WouldBlock)
2361
out
SocketError
sendErr);
2367
if (sendErr ==
SocketError
.WouldBlock)
2414
if (!TryDrainPendingToSocket(out
SocketError
leftoverErr))
2416
if (leftoverErr ==
SocketError
.WouldBlock)
2436
out
SocketError
sendErr);
2442
if (sendErr ==
SocketError
.WouldBlock)
System.Net.Sockets (700)
src\runtime\src\libraries\Common\src\System\Net\IPEndPointExtensions.cs (1)
29
throw new SocketException((int)
SocketError
.AddressFamilyNotSupported);
src\runtime\src\libraries\Common\src\System\Net\Sockets\SocketErrorPal.Unix.cs (88)
20
internal static
SocketError
GetSocketErrorForNativeError(Interop.Error errno) => errno switch
22
Interop.Error.EACCES =>
SocketError
.AccessDenied,
23
Interop.Error.EADDRINUSE =>
SocketError
.AddressAlreadyInUse,
24
Interop.Error.EADDRNOTAVAIL =>
SocketError
.AddressNotAvailable,
25
Interop.Error.EAFNOSUPPORT =>
SocketError
.AddressFamilyNotSupported,
26
Interop.Error.EAGAIN =>
SocketError
.WouldBlock,
27
Interop.Error.EALREADY =>
SocketError
.AlreadyInProgress,
28
Interop.Error.EBADF =>
SocketError
.OperationAborted,
29
Interop.Error.ECANCELED =>
SocketError
.OperationAborted,
30
Interop.Error.ECONNABORTED =>
SocketError
.ConnectionAborted,
31
Interop.Error.ECONNREFUSED =>
SocketError
.ConnectionRefused,
32
Interop.Error.ECONNRESET =>
SocketError
.ConnectionReset,
33
Interop.Error.EDESTADDRREQ =>
SocketError
.DestinationAddressRequired,
34
Interop.Error.EFAULT =>
SocketError
.Fault,
35
Interop.Error.EHOSTDOWN =>
SocketError
.HostDown,
36
Interop.Error.ENXIO =>
SocketError
.HostNotFound, // not perfect, but closest match available
37
Interop.Error.EHOSTUNREACH =>
SocketError
.HostUnreachable,
38
Interop.Error.EINPROGRESS =>
SocketError
.InProgress,
39
Interop.Error.EINTR =>
SocketError
.Interrupted,
40
Interop.Error.EINVAL =>
SocketError
.InvalidArgument,
41
Interop.Error.EISCONN =>
SocketError
.IsConnected,
42
Interop.Error.EMFILE =>
SocketError
.TooManyOpenSockets,
43
Interop.Error.EMSGSIZE =>
SocketError
.MessageSize,
44
Interop.Error.ENETDOWN =>
SocketError
.NetworkDown,
45
Interop.Error.ENETRESET =>
SocketError
.NetworkReset,
46
Interop.Error.ENETUNREACH =>
SocketError
.NetworkUnreachable,
47
Interop.Error.ENFILE =>
SocketError
.TooManyOpenSockets,
48
Interop.Error.ENOBUFS =>
SocketError
.NoBufferSpaceAvailable,
49
Interop.Error.ENODATA =>
SocketError
.NoData,
50
Interop.Error.ENOENT =>
SocketError
.AddressNotAvailable,
51
Interop.Error.ENOPROTOOPT =>
SocketError
.ProtocolOption,
52
Interop.Error.ENOTCONN =>
SocketError
.NotConnected,
53
Interop.Error.ENOTSOCK =>
SocketError
.NotSocket,
54
Interop.Error.ENOTSUP =>
SocketError
.OperationNotSupported,
55
Interop.Error.EPERM =>
SocketError
.AccessDenied,
56
Interop.Error.EPIPE =>
SocketError
.Shutdown,
57
Interop.Error.EPFNOSUPPORT =>
SocketError
.ProtocolFamilyNotSupported,
58
Interop.Error.EPROTONOSUPPORT =>
SocketError
.ProtocolNotSupported,
59
Interop.Error.EPROTOTYPE =>
SocketError
.ProtocolType,
60
Interop.Error.ESOCKTNOSUPPORT =>
SocketError
.SocketNotSupported,
61
Interop.Error.ESHUTDOWN =>
SocketError
.Disconnecting,
62
Interop.Error.SUCCESS =>
SocketError
.Success,
63
Interop.Error.ETIMEDOUT =>
SocketError
.TimedOut,
64
_ =>
SocketError
.SocketError, // unknown native error, just treat it as a generic SocketError
67
private static Interop.Error GetNativeErrorForSocketErrorHelper(
SocketError
error) => error switch
75
SocketError
.AccessDenied => Interop.Error.EACCES, // could also have been EPERM
76
SocketError
.AddressAlreadyInUse => Interop.Error.EADDRINUSE,
77
SocketError
.AddressNotAvailable => Interop.Error.EADDRNOTAVAIL,
78
SocketError
.AddressFamilyNotSupported => Interop.Error.EAFNOSUPPORT,
79
SocketError
.AlreadyInProgress => Interop.Error.EALREADY,
80
SocketError
.ConnectionAborted => Interop.Error.ECONNABORTED,
81
SocketError
.ConnectionRefused => Interop.Error.ECONNREFUSED,
82
SocketError
.ConnectionReset => Interop.Error.ECONNRESET,
83
SocketError
.DestinationAddressRequired => Interop.Error.EDESTADDRREQ,
84
SocketError
.Disconnecting => Interop.Error.ESHUTDOWN,
85
SocketError
.Fault => Interop.Error.EFAULT,
86
SocketError
.HostDown => Interop.Error.EHOSTDOWN,
87
SocketError
.HostNotFound => Interop.Error.EHOSTNOTFOUND,
88
SocketError
.HostUnreachable => Interop.Error.EHOSTUNREACH,
89
SocketError
.InProgress => Interop.Error.EINPROGRESS,
90
SocketError
.Interrupted => Interop.Error.EINTR,
91
SocketError
.InvalidArgument => Interop.Error.EINVAL,
92
SocketError
.IOPending => Interop.Error.EINPROGRESS,
93
SocketError
.IsConnected => Interop.Error.EISCONN,
94
SocketError
.MessageSize => Interop.Error.EMSGSIZE,
95
SocketError
.NetworkDown => Interop.Error.ENETDOWN,
96
SocketError
.NetworkReset => Interop.Error.ENETRESET,
97
SocketError
.NetworkUnreachable => Interop.Error.ENETUNREACH,
98
SocketError
.NoBufferSpaceAvailable => Interop.Error.ENOBUFS,
99
SocketError
.NoData => Interop.Error.ENODATA,
100
SocketError
.NotConnected => Interop.Error.ENOTCONN,
101
SocketError
.NotSocket => Interop.Error.ENOTSOCK,
102
SocketError
.OperationAborted => Interop.Error.ECANCELED,
103
SocketError
.OperationNotSupported => Interop.Error.ENOTSUP,
104
SocketError
.ProtocolFamilyNotSupported => Interop.Error.EPFNOSUPPORT,
105
SocketError
.ProtocolNotSupported => Interop.Error.EPROTONOSUPPORT,
106
SocketError
.ProtocolOption => Interop.Error.ENOPROTOOPT,
107
SocketError
.ProtocolType => Interop.Error.EPROTOTYPE,
108
SocketError
.Shutdown => Interop.Error.EPIPE,
109
SocketError
.SocketNotSupported => Interop.Error.ESOCKTNOSUPPORT,
110
SocketError
.Success => Interop.Error.SUCCESS,
111
SocketError
.TimedOut => Interop.Error.ETIMEDOUT,
112
SocketError
.TooManyOpenSockets => Interop.Error.ENFILE, // could also have been EMFILE
113
SocketError
.TryAgain => Interop.Error.EAGAIN, // not a perfect mapping, but better than nothing
114
SocketError
.WouldBlock => Interop.Error.EAGAIN,
115
SocketError
.SocketError => Interop.Error.ESOCKETERROR,
119
internal static Interop.Error GetNativeErrorForSocketError(
SocketError
error)
130
internal static bool TryGetNativeErrorForSocketError(
SocketError
error, out Interop.Error errno)
src\runtime\src\libraries\Common\src\System\Net\Sockets\SocketExceptionFactory.Unix.cs (1)
13
if (SocketErrorPal.TryGetNativeErrorForSocketError((
SocketError
)socketError, out Interop.Error interopErr))
System\Net\Sockets\SafeSocketHandle.cs (1)
152
ret = !OwnsHandle || DoCloseHandle(abortive) ==
SocketError
.Success;
System\Net\Sockets\SafeSocketHandle.Unix.cs (4)
85
internal void RegisterConnectResult(
SocketError
error)
89
case
SocketError
.Success:
90
case
SocketError
.WouldBlock:
248
private unsafe
SocketError
DoCloseHandle(bool abortive)
System\Net\Sockets\SafeSocketHandle.Unix.OptionTracking.cs (8)
42
SocketError
errorCode = SocketPal.GetLingerOption(this, out lingerOption);
43
if (errorCode !=
SocketError
.Success)
71
SocketError
errorCode = SocketPal.GetSockOpt(this, level, name, out values[i]);
72
if (errorCode !=
SocketError
.Success)
90
SocketError
errorCode = SocketPal.SetLingerOption(this, lingerOption);
91
if (NetEventSource.Log.IsEnabled() && errorCode !=
SocketError
.Success) NetEventSource.Info(this, $"SetLingerOption returned errorCode:{errorCode}");
103
SocketError
errorCode = SocketPal.SetSockOpt(this, level, name, values[i]);
104
if (NetEventSource.Log.IsEnabled() && errorCode !=
SocketError
.Success) NetEventSource.Info(this, $"GetSockOpt({level},{name}) returned errorCode:{errorCode}");
System\Net\Sockets\Socket.cs (182)
86
SocketError
errorCode = SocketPal.CreateSocket(addressFamily, socketType, protocolType, out _handle);
87
if (errorCode !=
SocketError
.Success)
146
if (SocketPal.GetSockName(handle, bufferPtr, &bufferLength) !=
SocketError
.Success)
194
case
SocketError
.Success:
221
case
SocketError
.InvalidArgument:
284
SocketError
errorCode = SocketPal.GetAvailable(_handle, out argp);
289
if (errorCode !=
SocketError
.Success)
322
SocketError
errorCode = SocketPal.GetSockName(_handle, ptr, &size);
323
if (errorCode !=
SocketError
.Success)
365
SocketError
errorCode = SocketPal.GetPeerName(
369
if (errorCode !=
SocketError
.Success)
425
SocketError
errorCode = InternalSetBlocking(value, out current);
427
if (errorCode !=
SocketError
.Success)
812
UpdateStatusAfterSocketErrorAndThrowException(
SocketError
.InvalidArgument);
816
SocketError
errorCode = SocketPal.Bind(
822
if (errorCode !=
SocketError
.Success)
1021
SocketError
errorCode = SocketPal.Listen(_handle, backlog);
1024
if (errorCode !=
SocketError
.Success)
1062
SocketError
errorCode;
1075
SocketsTelemetry.Log.AfterAccept(
SocketError
.Interrupted, ex.Message);
1080
if (errorCode !=
SocketError
.Success)
1091
SocketsTelemetry.Log.AfterAccept(
SocketError
.Success);
1135
SocketError
errorCode;
1137
if (errorCode !=
SocketError
.Success)
1144
public int Send(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out
SocketError
errorCode)
1162
if (errorCode !=
SocketError
.Success)
1186
SocketError
errorCode;
1188
if (errorCode !=
SocketError
.Success)
1195
public int Send(byte[] buffer, int offset, int size, SocketFlags socketFlags, out
SocketError
errorCode)
1210
if (errorCode !=
SocketError
.Success)
1240
int bytesTransferred = Send(buffer, socketFlags, out
SocketError
errorCode);
1241
return errorCode ==
SocketError
.Success ?
1246
public int Send(ReadOnlySpan<byte> buffer, SocketFlags socketFlags, out
SocketError
errorCode)
1256
if (errorCode !=
SocketError
.Success)
1370
SocketError
errorCode = SocketPal.SendTo(_handle, buffer, offset, size, socketFlags, socketAddress.Buffer.Slice(0, socketAddress.Size), out bytesTransferred);
1373
if (errorCode !=
SocketError
.Success)
1452
SocketError
errorCode = SocketPal.SendTo(_handle, buffer, socketFlags, socketAddress.Buffer.Slice(0, socketAddress.Size), out bytesTransferred);
1455
if (errorCode !=
SocketError
.Success)
1493
SocketError
errorCode = SocketPal.SendTo(_handle, buffer, socketFlags, socketAddress.Buffer.Slice(0, socketAddress.Size), out bytesTransferred);
1496
if (errorCode !=
SocketError
.Success)
1538
SocketError
errorCode;
1540
if (errorCode !=
SocketError
.Success)
1547
public int Receive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out
SocketError
errorCode)
1561
if (errorCode !=
SocketError
.Success)
1585
int bytesTransferred = Receive(buffer, socketFlags, out
SocketError
errorCode);
1586
return errorCode ==
SocketError
.Success ?
1591
public int Receive(Span<byte> buffer, SocketFlags socketFlags, out
SocketError
errorCode)
1603
if (errorCode !=
SocketError
.Success)
1629
SocketError
errorCode;
1631
if (errorCode !=
SocketError
.Success)
1638
public int Receive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out
SocketError
errorCode)
1659
if (errorCode !=
SocketError
.Success)
1698
SocketError
errorCode = SocketPal.ReceiveMessageFrom(this, _handle, buffer, offset, size, ref socketFlags, socketAddress, out receiveAddress, out ipPacketInformation, out bytesTransferred);
1702
if (errorCode !=
SocketError
.Success && errorCode !=
SocketError
.MessageSize)
1709
if (errorCode ==
SocketError
.Success && SocketType == SocketType.Dgram) SocketsTelemetry.Log.DatagramReceived();
1785
SocketError
errorCode = SocketPal.ReceiveMessageFrom(this, _handle, buffer, ref socketFlags, socketAddress, out receiveAddress, out ipPacketInformation, out bytesTransferred);
1789
if (errorCode !=
SocketError
.Success && errorCode !=
SocketError
.MessageSize)
1796
if (errorCode ==
SocketError
.Success && SocketType == SocketType.Dgram) SocketsTelemetry.Log.DatagramReceived();
1840
SocketError
errorCode = SocketPal.ReceiveFrom(_handle, buffer, offset, size, socketFlags, socketAddress.Buffer, out int socketAddressLength, out bytesTransferred);
1845
if (errorCode !=
SocketError
.Success)
1851
if (socketException.SocketErrorCode !=
SocketError
.MessageSize)
1964
SocketError
errorCode = SocketPal.ReceiveFrom(_handle, buffer, socketFlags, socketAddress.Buffer, out int socketAddressLength, out bytesTransferred);
1969
if (errorCode !=
SocketError
.Success)
1975
if (socketException.SocketErrorCode !=
SocketError
.MessageSize)
2042
SocketError
errorCode = SocketPal.ReceiveFrom(_handle, buffer, socketFlags, receivedAddress.Buffer, out int socketAddressSize, out bytesTransferred);
2045
if (errorCode !=
SocketError
.Success)
2073
SocketError
errorCode = SocketPal.WindowsIoctl(_handle, ioControlCode, optionInValue, optionOutValue, out realOptionLength);
2078
if (errorCode !=
SocketError
.Success)
2107
SocketError
errorCode = SocketPal.SetSockOpt(_handle, optionLevel, optionName, optionValue);
2112
if (errorCode !=
SocketError
.Success)
2185
SocketError
errorCode = SocketPal.SetRawSockOpt(_handle, optionLevel, optionName, optionValue);
2189
if (errorCode !=
SocketError
.Success)
2216
SocketError
errorCode = SocketPal.GetSockOpt(
2225
if (errorCode !=
SocketError
.Success)
2240
SocketError
errorCode = SocketPal.GetSockOpt(
2250
if (errorCode !=
SocketError
.Success)
2264
SocketError
errorCode = SocketPal.GetSockOpt(
2274
if (errorCode !=
SocketError
.Success)
2306
SocketError
errorCode = SocketPal.GetRawSockOpt(_handle, optionLevel, optionName, optionValue, ref realOptionLength);
2310
if (errorCode !=
SocketError
.Success)
2362
SocketError
errorCode = SocketPal.Poll(_handle, microSeconds, mode, out status);
2366
if (errorCode !=
SocketError
.Success)
2426
SocketError
errorCode = SocketPal.Select(checkRead, checkWrite, checkError, microSeconds);
2429
if (errorCode !=
SocketError
.Success)
2483
SocketError
errorCode;
2490
if (errorCode !=
SocketError
.Success)
2510
public IAsyncResult? BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, out
SocketError
errorCode, AsyncCallback? callback, object? state)
2522
errorCode =
SocketError
.Success;
2533
public IAsyncResult? BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out
SocketError
errorCode, AsyncCallback? callback, object? state)
2544
errorCode =
SocketError
.Success;
2550
public int EndSend(IAsyncResult asyncResult, out
SocketError
errorCode) =>
2593
public IAsyncResult? BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out
SocketError
errorCode, AsyncCallback? callback, object? state)
2605
errorCode =
SocketError
.Success;
2615
public IAsyncResult? BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out
SocketError
errorCode, AsyncCallback? callback, object? state)
2626
errorCode =
SocketError
.Success;
2632
public int EndReceive(IAsyncResult asyncResult, out
SocketError
errorCode) =>
2635
private static int EndSendReceive(IAsyncResult asyncResult, out
SocketError
errorCode)
2643
errorCode =
SocketError
.Success;
2791
SocketError
errorCode = SocketPal.Shutdown(_handle, _isConnected, _isDisconnected, how);
2796
if (errorCode !=
SocketError
.Success && errorCode !=
SocketError
.NotSocket)
2838
SocketError
socketError;
2845
SocketsTelemetry.Log.AfterAccept(
SocketError
.Interrupted, ex.Message);
2852
return socketError ==
SocketError
.IOPending;
2931
SocketsTelemetry.Log.AfterConnect(
SocketError
.NotSocket, e.ConnectActivity, ex.Message);
2941
SocketError
socketError = canUseConnectEx ?
2944
pending = socketError ==
SocketError
.IOPending;
2948
SocketsTelemetry.Log.AfterConnect(
SocketError
.NotSocket, e.ConnectActivity, ex.Message);
3031
SocketError
socketError;
3043
return socketError ==
SocketError
.IOPending;
3056
SocketError
socketError;
3068
return socketError ==
SocketError
.IOPending;
3117
SocketError
socketError;
3129
bool pending = (socketError ==
SocketError
.IOPending);
3165
SocketError
socketError;
3177
return socketError ==
SocketError
.IOPending;
3190
SocketError
socketError;
3202
return socketError ==
SocketError
.IOPending;
3223
SocketError
socketError;
3235
return socketError ==
SocketError
.IOPending;
3272
SocketError
socketError;
3292
return socketError ==
SocketError
.IOPending;
3343
SocketError
errorCode;
3350
SocketsTelemetry.Log.AfterConnect(
SocketError
.NotSocket, activity, ex.Message);
3355
if (errorCode !=
SocketError
.Success)
3368
SocketsTelemetry.Log.AfterConnect(
SocketError
.Success, activity);
3424
SocketError
errorCode;
3454
if (errorCode !=
SocketError
.Success)
3464
if (errorCode != (
SocketError
)0)
3476
if (errorCode !=
SocketError
.Success || dataAvailable != 0)
3588
UpdateStatusAfterSocketOptionErrorAndThrowException(
SocketError
.ProtocolOption);
3598
SocketError
errorCode;
3615
errorCode ==
SocketError
.Success)
3626
if (errorCode !=
SocketError
.Success)
3634
SocketError
errorCode = SocketPal.SetMulticastOption(_handle, optionName, MR);
3639
if (errorCode !=
SocketError
.Success)
3648
SocketError
errorCode = SocketPal.SetIPv6MulticastOption(_handle, optionName, MR);
3653
if (errorCode !=
SocketError
.Success)
3663
SocketError
errorCode = SocketPal.SetLingerOption(_handle, lref);
3668
if (errorCode !=
SocketError
.Success)
3679
SocketError
errorCode = SocketPal.GetLingerOption(_handle, out lingerOption);
3684
if (errorCode !=
SocketError
.Success)
3695
SocketError
errorCode = SocketPal.GetMulticastOption(_handle, optionName, out multicastOption);
3700
if (errorCode !=
SocketError
.Success)
3712
SocketError
errorCode = SocketPal.GetIPv6MulticastOption(_handle, optionName, out multicastOption);
3717
if (errorCode !=
SocketError
.Success)
3727
private
SocketError
InternalSetBlocking(bool desired, out bool current)
3732
return
SocketError
.Success;
3737
SocketError
errorCode;
3744
errorCode =
SocketError
.NotSocket;
3751
if (errorCode ==
SocketError
.Success)
3889
private void UpdateStatusAfterSocketOptionErrorAndThrowException(
SocketError
error, [CallerMemberName] string? callerName = null)
3892
bool disconnectOnFailure = error !=
SocketError
.ProtocolOption &&
3893
error !=
SocketError
.OperationNotSupported;
3897
private void UpdateStatusAfterSocketErrorAndThrowException(
SocketError
error, bool disconnectOnFailure = true, [CallerMemberName] string? callerName = null)
3914
internal void UpdateStatusAfterSocketError(
SocketError
errorCode, bool disconnectOnFailure = true)
3920
if (disconnectOnFailure && _isConnected && (_handle.IsInvalid || (errorCode !=
SocketError
.WouldBlock &&
3921
errorCode !=
SocketError
.IOPending && errorCode !=
SocketError
.NoBufferSpaceAvailable &&
3922
errorCode !=
SocketError
.TimedOut && errorCode !=
SocketError
.OperationAborted)))
3930
private bool CheckErrorAndUpdateStatus(
SocketError
errorCode)
3932
if (errorCode ==
SocketError
.Success || errorCode ==
SocketError
.IOPending)
3982
private void UpdateReceiveSocketErrorForDisposed(ref
SocketError
socketError, int bytesTransferred)
3989
socketError = IsConnectionOriented ?
SocketError
.ConnectionAborted :
SocketError
.Interrupted;
3993
private void UpdateSendSocketErrorForDisposed(ref
SocketError
socketError)
3997
socketError = IsConnectionOriented ?
SocketError
.ConnectionAborted :
SocketError
.Interrupted;
4001
private void UpdateConnectSocketErrorForDisposed(ref
SocketError
socketError)
4005
socketError =
SocketError
.NotSocket;
4009
private void UpdateAcceptSocketErrorForDisposed(ref
SocketError
socketError)
4013
socketError =
SocketError
.Interrupted;
4026
throw new SocketException((int)
SocketError
.IsConnected);
4047
private static
SocketError
GetSocketErrorFromFaultedTask(Task t)
4053
return
SocketError
.OperationAborted;
4060
ObjectDisposedException =>
SocketError
.OperationAborted,
4061
OperationCanceledException =>
SocketError
.OperationAborted,
4062
_ =>
SocketError
.SocketError
System\Net\Sockets\Socket.Tasks.cs (41)
162
throw new SocketException((int)
SocketError
.IsConnected);
852
if (saea.SocketError ==
SocketError
.Success)
875
SocketError
error = saea.SocketError;
890
if (error ==
SocketError
.Success)
901
private static Exception GetException(
SocketError
error, bool wrapExceptionsInIOExceptions = false)
1030
SocketError
error = SocketError;
1036
return error ==
SocketError
.Success ?
1052
SocketError
error = SocketError;
1056
return error ==
SocketError
.Success ?
1071
SocketError
error = SocketError;
1075
return error ==
SocketError
.Success ?
1089
SocketError
error = SocketError;
1093
return error ==
SocketError
.Success ?
1110
SocketError
error = SocketError;
1114
return error ==
SocketError
.Success ?
1130
SocketError
error = SocketError;
1134
return error ==
SocketError
.Success ?
1147
SocketError
error = SocketError;
1151
return error ==
SocketError
.Success ?
1164
SocketError
error = SocketError;
1168
return error ==
SocketError
.Success ?
1182
SocketError
error = SocketError;
1186
return error ==
SocketError
.Success ?
1207
SocketError
error = SocketError;
1211
return error ==
SocketError
.Success ?
1224
SocketError
error = SocketError;
1228
return error ==
SocketError
.Success ?
1254
SocketError
error = SocketError;
1260
if (error !=
SocketError
.Success)
1274
SocketError
error = SocketError;
1279
if (error !=
SocketError
.Success)
1292
SocketError
error = SocketError;
1300
if (error !=
SocketError
.Success)
1314
SocketError
error = SocketError;
1321
if (error !=
SocketError
.Success)
1336
SocketError
error = SocketError;
1345
if (error !=
SocketError
.Success)
1355
private void ThrowException(
SocketError
error, CancellationToken cancellationToken)
1360
if (error is
SocketError
.OperationAborted or
SocketError
.ConnectionAborted)
1368
private Exception CreateException(
SocketError
error, bool forAsyncThrow = true)
System\Net\Sockets\Socket.Unix.cs (13)
73
throw new SocketException((int)
SocketError
.NotSocket);
81
throw new SocketException((int)
SocketError
.NotSocket);
124
SocketError
errorCode = ReplaceHandle();
125
if (errorCode !=
SocketError
.Success)
145
return ReplaceHandle() ==
SocketError
.Success;
148
internal unsafe
SocketError
ReplaceHandle()
158
SocketError
errorCode = SocketPal.CreateSocket(_addressFamily, _socketType, _protocolType, out SafeSocketHandle newHandle);
163
if (errorCode !=
SocketError
.Success)
177
return
SocketError
.Success;
192
throw new SocketException((int)
SocketError
.InvalidArgument);
220
SocketError
errorCode =
SocketError
.Success;
241
if (errorCode !=
SocketError
.Success)
System\Net\Sockets\SocketAsyncContext.Unix.cs (99)
121
public
SocketError
ErrorCode;
149
ErrorCode =
SocketError
.OperationAborted;
170
public Action<int, Memory<byte>, SocketFlags,
SocketError
>? Callback { get; set; }
193
SocketError
ec = ErrorCode;
221
SocketError
ec = ErrorCode;
254
public Action<int, Memory<byte>, SocketFlags,
SocketError
>? Callback { get; set; }
276
ErrorCode =
SocketError
.Success;
291
if (completed && ErrorCode ==
SocketError
.Success)
306
SocketError
ec = ErrorCode;
326
if (completed && ErrorCode ==
SocketError
.Success)
339
SocketError
ec = ErrorCode;
360
if (completed && ErrorCode ==
SocketError
.Success)
382
public Action<int, Memory<byte>, SocketFlags, IPPacketInformation,
SocketError
>? Callback { get; set; }
387
if (completed && ErrorCode ==
SocketError
.Success)
412
public Action<int, Memory<byte>, SocketFlags, IPPacketInformation,
SocketError
>? Callback { get; set; }
417
if (completed && ErrorCode ==
SocketError
.Success)
434
public Action<IntPtr, Memory<byte>,
SocketError
>? Callback { get; set; }
439
Debug.Assert(ErrorCode ==
SocketError
.Success || AcceptedFileDescriptor == (IntPtr)(-1), $"Unexpected values: ErrorCode={ErrorCode}, AcceptedFileDescriptor={AcceptedFileDescriptor}");
440
if (ErrorCode ==
SocketError
.Success)
452
SocketError
ec = ErrorCode;
478
if (!result || ErrorCode !=
SocketError
.Success || Buffer.Length == 0)
504
SocketError
ec = ErrorCode;
523
public Action<long,
SocketError
>? Callback { get; set; }
639
operation.ErrorCode =
SocketError
.TimedOut;
643
operation.ErrorCode =
SocketError
.OperationAborted;
647
private bool ShouldRetrySyncOperation(out
SocketError
errorCode)
651
errorCode =
SocketError
.Success; // Will be ignored
656
errorCode =
SocketError
.TimedOut;
660
public
SocketError
Accept(Memory<byte> socketAddress, out int socketAddressLen, out IntPtr acceptedFd)
664
SocketError
errorCode;
669
Debug.Assert(errorCode ==
SocketError
.Success || acceptedFd == (IntPtr)(-1), $"Unexpected values: errorCode={errorCode}, acceptedFd={acceptedFd}");
685
public
SocketError
AcceptAsync(Memory<byte> socketAddress, out int socketAddressLen, out IntPtr acceptedFd, Action<IntPtr, Memory<byte>,
SocketError
> callback, CancellationToken cancellationToken)
692
SocketError
errorCode;
697
Debug.Assert(errorCode ==
SocketError
.Success || acceptedFd == (IntPtr)(-1), $"Unexpected values: errorCode={errorCode}, acceptedFd={acceptedFd}");
723
public
SocketError
Connect(Memory<byte> socketAddress)
732
SocketError
errorCode;
752
public
SocketError
ConnectAsync(Memory<byte> socketAddress, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback, Memory<byte> buffer, out int sentBytes, CancellationToken cancellationToken)
762
SocketError
errorCode;
775
if (errorCode ==
SocketError
.Success && remains > 0)
781
Action<int, Memory<byte>, SocketFlags,
SocketError
> connectCallback = callback;
790
if (remains == 0 || errorCode !=
SocketError
.IOPending)
822
public
SocketError
Receive(Memory<byte> buffer, SocketFlags flags, int timeout, out int bytesReceived)
827
public
SocketError
Receive(Span<byte> buffer, SocketFlags flags, int timeout, out int bytesReceived)
832
public
SocketError
ReceiveAsync(Memory<byte> buffer, SocketFlags flags, out int bytesReceived, out SocketFlags receivedFlags, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback, CancellationToken cancellationToken)
837
public
SocketError
ReceiveFrom(Memory<byte> buffer, ref SocketFlags flags, Memory<byte> socketAddress, out int socketAddressLen, int timeout, out int bytesReceived)
844
SocketError
errorCode;
870
public unsafe
SocketError
ReceiveFrom(Span<byte> buffer, ref SocketFlags flags, Memory<byte> socketAddress, out int socketAddressLen, int timeout, out int bytesReceived)
875
SocketError
errorCode;
904
public
SocketError
ReceiveAsync(Memory<byte> buffer, SocketFlags flags, out int bytesReceived, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback, CancellationToken cancellationToken = default)
908
SocketError
errorCode;
938
public
SocketError
ReceiveFromAsync(Memory<byte> buffer, SocketFlags flags, Memory<byte> socketAddress, out int socketAddressLen, out int bytesReceived, out SocketFlags receivedFlags, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback, CancellationToken cancellationToken = default)
942
SocketError
errorCode;
976
public
SocketError
Receive(IList<ArraySegment<byte>> buffers, SocketFlags flags, int timeout, out int bytesReceived)
981
public
SocketError
ReceiveAsync(IList<ArraySegment<byte>> buffers, SocketFlags flags, out int bytesReceived, out SocketFlags receivedFlags, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback)
986
public
SocketError
ReceiveFrom(IList<ArraySegment<byte>> buffers, ref SocketFlags flags, Memory<byte> socketAddress, out int socketAddressLen, int timeout, out int bytesReceived)
993
SocketError
errorCode;
1018
public
SocketError
ReceiveFromAsync(IList<ArraySegment<byte>> buffers, SocketFlags flags, Memory<byte> socketAddress, out int socketAddressLen, out int bytesReceived, out SocketFlags receivedFlags, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback)
1022
SocketError
errorCode;
1056
public
SocketError
ReceiveMessageFrom(
1064
SocketError
errorCode;
1093
public unsafe
SocketError
ReceiveMessageFrom(
1101
SocketError
errorCode;
1133
public
SocketError
ReceiveMessageFromAsync(Memory<byte> buffer, IList<ArraySegment<byte>>? buffers, SocketFlags flags, Memory<byte> socketAddress, out int socketAddressLen, bool isIPv4, bool isIPv6, out int bytesReceived, out SocketFlags receivedFlags, out IPPacketInformation ipPacketInformation, Action<int, Memory<byte>, SocketFlags, IPPacketInformation,
SocketError
> callback, CancellationToken cancellationToken = default)
1137
SocketError
errorCode;
1175
public
SocketError
Send(ReadOnlySpan<byte> buffer, SocketFlags flags, int timeout, out int bytesSent) =>
1178
public
SocketError
Send(byte[] buffer, int offset, int count, SocketFlags flags, int timeout, out int bytesSent)
1183
public
SocketError
SendAsync(Memory<byte> buffer, int offset, int count, SocketFlags flags, out int bytesSent, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback, CancellationToken cancellationToken)
1189
public
SocketError
SendTo(byte[] buffer, int offset, int count, SocketFlags flags, Memory<byte> socketAddress, int timeout, out int bytesSent)
1196
SocketError
errorCode;
1221
public unsafe
SocketError
SendTo(ReadOnlySpan<byte> buffer, SocketFlags flags, Memory<byte> socketAddress, int timeout, out int bytesSent)
1228
SocketError
errorCode;
1257
public
SocketError
SendToAsync(Memory<byte> buffer, int offset, int count, SocketFlags flags, Memory<byte> socketAddress, ref int bytesSent, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback, CancellationToken cancellationToken = default)
1261
SocketError
errorCode;
1292
public
SocketError
Send(IList<ArraySegment<byte>> buffers, SocketFlags flags, int timeout, out int bytesSent)
1297
public
SocketError
SendAsync(IList<ArraySegment<byte>> buffers, SocketFlags flags, out int bytesSent, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback)
1302
public
SocketError
SendTo(IList<ArraySegment<byte>> buffers, SocketFlags flags, Memory<byte> socketAddress, int timeout, out int bytesSent)
1311
SocketError
errorCode;
1336
public
SocketError
SendToAsync(IList<ArraySegment<byte>> buffers, SocketFlags flags, Memory<byte> socketAddress, out int bytesSent, Action<int, Memory<byte>, SocketFlags,
SocketError
> callback)
1343
SocketError
errorCode;
1374
public
SocketError
SendFile(SafeFileHandle fileHandle, long offset, long count, int timeout, out long bytesSent)
1381
SocketError
errorCode;
1404
public
SocketError
SendFileAsync(SafeFileHandle fileHandle, long offset, long count, out long bytesSent, Action<long,
SocketError
> callback, CancellationToken cancellationToken = default)
1409
SocketError
errorCode;
1438
private static
SocketError
GetSocketErrorForNonCompleted(AsyncResult result)
1441
return result == AsyncResult.Pending ?
SocketError
.IOPending :
SocketError
.OperationAborted;
System\Net\Sockets\SocketAsyncEventArgs.cs (25)
55
private
SocketError
_socketError;
287
public
SocketError
SocketError
431
internal void SetResults(
SocketError
socketError, int bytesTransferred, SocketFlags flags)
447
_socketError =
SocketError
.Success;
460
_socketError =
SocketError
.OperationAborted;
464
_socketError =
SocketError
.SocketError;
631
internal void FinishOperationSyncFailure(
SocketError
socketError, int bytesTransferred, SocketFlags flags)
663
internal void FinishOperationAsyncFailure(
SocketError
socketError, int bytesTransferred, SocketFlags flags)
748
SocketError
lastError =
SocketError
.NoData;
816
if (internalArgs.SocketError ==
SocketError
.Success)
824
lastError =
SocketError
.OperationAborted;
844
caughtException = new SocketException((int)
SocketError
.OperationAborted);
883
(caughtException is SocketException se && se.SocketErrorCode ==
SocketError
.OperationAborted))
897
SetResults(
SocketError
.Success, internalArgs.BytesTransferred, internalArgs.SocketFlags);
955
public void SetResults(Socket? socket,
SocketError
socketError, int bytesTransferred, SocketFlags flags, Exception? exception)
960
if (socketError ==
SocketError
.Success && exception == null)
966
_saea.SetResults(
SocketError
.Success, bytesTransferred, flags);
998
SetResults(
SocketError
.Success, bytesTransferred, flags);
1005
SocketError
socketError;
1014
if (socketError ==
SocketError
.Success)
1041
if (socketError ==
SocketError
.Success)
1146
private void FinishOperationSync(
SocketError
socketError, int bytesTransferred, SocketFlags flags)
1148
Debug.Assert(socketError !=
SocketError
.IOPending);
1150
if (socketError ==
SocketError
.Success)
System\Net\Sockets\SocketAsyncEventArgs.Unix.cs (44)
16
private Action<int, Memory<byte>, SocketFlags,
SocketError
>? _transferCompletionCallback;
26
private void AcceptCompletionCallback(IntPtr acceptedFileDescriptor, Memory<byte> socketAddress,
SocketError
socketError)
33
private void CompleteAcceptOperation(IntPtr acceptedFileDescriptor, Memory<byte> socketAddress,
SocketError
socketError)
36
if (socketError ==
SocketError
.Success)
46
internal
SocketError
DoOperationAccept(Socket _ /*socket*/, SafeSocketHandle handle, SafeSocketHandle? acceptHandle, CancellationToken cancellationToken)
58
SocketError
socketError = handle.AsyncContext.AcceptAsync(_acceptBuffer!, out int socketAddressLen, out acceptedFd, AcceptCompletionCallback, cancellationToken);
60
if (socketError !=
SocketError
.IOPending)
69
private void ConnectCompletionCallback(int bytesTransferred, Memory<byte> socketAddress, SocketFlags receivedFlags,
SocketError
socketError)
74
internal
SocketError
DoOperationConnectEx(Socket _ /*socket*/, SafeSocketHandle handle, CancellationToken cancellationToken)
76
SocketError
socketError = handle.AsyncContext.ConnectAsync(_socketAddress!.Buffer, ConnectCompletionCallback, _buffer.Slice(_offset, _count), out int sentBytes, cancellationToken);
77
if (socketError !=
SocketError
.IOPending)
84
internal
SocketError
DoOperationConnect(SafeSocketHandle handle, CancellationToken cancellationToken)
86
SocketError
socketError = handle.AsyncContext.ConnectAsync(_socketAddress!.Buffer, ConnectCompletionCallback, Memory<byte>.Empty, out int _, cancellationToken);
87
if (socketError !=
SocketError
.IOPending)
94
internal
SocketError
DoOperationDisconnect(Socket socket, SafeSocketHandle handle, CancellationToken _ /*cancellationToken*/)
96
SocketError
socketError = SocketPal.Disconnect(socket, handle, _disconnectReuseSocket);
101
private Action<int, Memory<byte>, SocketFlags,
SocketError
> TransferCompletionCallback =>
104
private void TransferCompletionCallbackCore(int bytesTransferred, Memory<byte> socketAddress, SocketFlags receivedFlags,
SocketError
socketError)
117
internal
SocketError
DoOperationReceive(SafeSocketHandle handle, CancellationToken cancellationToken)
124
SocketError
errorCode;
144
if (errorCode !=
SocketError
.IOPending)
153
internal
SocketError
DoOperationReceiveFrom(SafeSocketHandle handle, CancellationToken cancellationToken)
159
SocketError
errorCode;
171
if (errorCode !=
SocketError
.IOPending)
180
private void ReceiveMessageFromCompletionCallback(int bytesTransferred, Memory<byte> socketAddress, SocketFlags receivedFlags, IPPacketInformation ipPacketInformation,
SocketError
errorCode)
196
internal
SocketError
DoOperationReceiveMessageFrom(Socket socket, SafeSocketHandle handle, CancellationToken cancellationToken)
209
SocketError
socketError = handle.AsyncContext.ReceiveMessageFromAsync(_buffer.Slice(_offset, _count), _bufferListInternal, _socketFlags, _socketAddress.Buffer, out socketAddressSize, isIPv4, isIPv6, out bytesReceived, out receivedFlags, out ipPacketInformation, ReceiveMessageFromCompletionCallback, cancellationToken);
210
if (socketError !=
SocketError
.IOPending)
219
internal
SocketError
DoOperationSend(SafeSocketHandle handle, CancellationToken cancellationToken)
225
SocketError
errorCode;
235
if (errorCode !=
SocketError
.IOPending)
244
internal
SocketError
DoOperationSendPackets(Socket socket, SafeSocketHandle _1 /*handle*/, CancellationToken cancellationToken)
290
if (error ==
SocketError
.Success)
300
return
SocketError
.IOPending;
303
internal
SocketError
DoOperationSendTo(SafeSocketHandle handle, CancellationToken cancellationToken)
309
SocketError
errorCode;
319
if (errorCode !=
SocketError
.IOPending)
345
private
SocketError
FinishOperationAccept(SocketAddress remoteSocketAddress)
367
return
SocketError
.Success;
370
private static
SocketError
FinishOperationConnect()
373
return
SocketError
.Success;
385
private void CompletionCallback(int bytesTransferred, SocketFlags flags,
SocketError
socketError)
387
if (socketError ==
SocketError
.Success)
395
socketError =
SocketError
.OperationAborted;
System\Net\Sockets\SocketPal.Unix.cs (162)
30
public static
SocketError
GetSocketErrorForErrorCode(Interop.Error errorCode)
59
public static unsafe
SocketError
CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, out SafeSocketHandle socket)
64
SocketError
errorCode;
70
errorCode =
SocketError
.Success;
626
public static unsafe bool TryCompleteAccept(SafeSocketHandle socket, Memory<byte> socketAddress, out int socketAddressLen, out IntPtr acceptedFd, out
SocketError
errorCode)
641
errorCode =
SocketError
.OperationAborted;
652
errorCode =
SocketError
.Success;
665
errorCode =
SocketError
.Success;
669
public static bool TryStartConnect(SafeSocketHandle socket, Memory<byte> socketAddress, out
SocketError
errorCode) => TryStartConnect(socket, socketAddress, out errorCode, Span<byte>.Empty, false, out int _ );
671
public static unsafe bool TryStartConnect(SafeSocketHandle socket, Memory<byte> socketAddress, out
SocketError
errorCode, Span<byte> data, bool tfo, out int sent)
678
errorCode =
SocketError
.IsConnected;
699
errorCode =
SocketError
.Success;
709
errorCode =
SocketError
.Success;
713
public static unsafe bool TryCompleteConnect(SafeSocketHandle socket, out
SocketError
errorCode)
741
errorCode =
SocketError
.OperationAborted;
748
errorCode =
SocketError
.SocketError;
754
errorCode =
SocketError
.Success;
759
errorCode =
SocketError
.Success;
767
public static bool TryCompleteReceiveFrom(SafeSocketHandle socket, Span<byte> buffer, SocketFlags flags, Span<byte> socketAddress, out int socketAddressLen, out int bytesReceived, out SocketFlags receivedFlags, out
SocketError
errorCode) =>
770
public static bool TryCompleteReceiveFrom(SafeSocketHandle socket, IList<ArraySegment<byte>> buffers, SocketFlags flags, Span<byte> socketAddress, out int socketAddressLen, out int bytesReceived, out SocketFlags receivedFlags, out
SocketError
errorCode) =>
774
private static unsafe bool TryCompleteZeroByteReceiveWasi(SafeSocketHandle socket, out
SocketError
errorCode)
789
errorCode =
SocketError
.Success;
793
public static unsafe bool TryCompleteReceive(SafeSocketHandle socket, Span<byte> buffer, SocketFlags flags, out int bytesReceived, out
SocketError
errorCode)
834
errorCode =
SocketError
.Success;
846
errorCode =
SocketError
.Success;
853
errorCode =
SocketError
.OperationAborted;
858
public static unsafe bool TryCompleteReceiveFrom(SafeSocketHandle socket, Span<byte> buffer, IList<ArraySegment<byte>>? buffers, SocketFlags flags, Span<byte> socketAddress, out int receivedSocketAddressLength, out int bytesReceived, out SocketFlags receivedFlags, out
SocketError
errorCode)
910
errorCode =
SocketError
.Success;
923
errorCode =
SocketError
.Success;
932
errorCode =
SocketError
.OperationAborted;
937
public static bool TryCompleteReceiveMessageFrom(SafeSocketHandle socket, Span<byte> buffer, IList<ArraySegment<byte>>? buffers, SocketFlags flags, Memory<byte> socketAddress, out int receivedSocketAddressLength, bool isIPv4, bool isIPv6, out int bytesReceived, out SocketFlags receivedFlags, out IPPacketInformation ipPacketInformation, out
SocketError
errorCode)
956
errorCode =
SocketError
.Success;
968
errorCode =
SocketError
.Success;
978
errorCode =
SocketError
.OperationAborted;
983
public static bool TryCompleteSendTo(SafeSocketHandle socket, Span<byte> buffer, ref int offset, ref int count, SocketFlags flags, ReadOnlySpan<byte> socketAddress, ref int bytesSent, out
SocketError
errorCode)
989
public static bool TryCompleteSendTo(SafeSocketHandle socket, ReadOnlySpan<byte> buffer, SocketFlags flags, ReadOnlySpan<byte> socketAddress, ref int bytesSent, out
SocketError
errorCode)
995
public static bool TryCompleteSendTo(SafeSocketHandle socket, IList<ArraySegment<byte>> buffers, ref int bufferIndex, ref int offset, SocketFlags flags, ReadOnlySpan<byte> socketAddress, ref int bytesSent, out
SocketError
errorCode)
1001
public static bool TryCompleteSendTo(SafeSocketHandle socket, ReadOnlySpan<byte> buffer, IList<ArraySegment<byte>>? buffers, ref int bufferIndex, ref int offset, ref int count, SocketFlags flags, ReadOnlySpan<byte> socketAddress, ref int bytesSent, out
SocketError
errorCode)
1029
errorCode =
SocketError
.OperationAborted;
1041
errorCode = successfulSend ?
SocketError
.Success :
SocketError
.WouldBlock;
1053
errorCode =
SocketError
.Success;
1063
errorCode =
SocketError
.TimedOut;
1070
public static bool TryCompleteSendFile(SafeSocketHandle socket, SafeFileHandle handle, ref long offset, ref long count, ref long bytesSent, out
SocketError
errorCode)
1084
errorCode =
SocketError
.OperationAborted;
1096
errorCode =
SocketError
.Success;
1102
errorCode =
SocketError
.Success;
1108
public static
SocketError
SetBlocking(SafeSocketHandle handle, bool shouldBlock, out bool willBlock)
1114
return
SocketError
.Success;
1117
public static unsafe
SocketError
GetSockName(SafeSocketHandle handle, byte* buffer, int* nameLen)
1120
return err == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(err);
1123
public static unsafe
SocketError
GetAvailable(SafeSocketHandle handle, out int available)
1129
return err == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(err);
1132
public static unsafe
SocketError
GetAtOutOfBandMark(SafeSocketHandle handle, out int atOutOfBandMark)
1138
return err == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(err);
1141
public static unsafe
SocketError
GetPeerName(SafeSocketHandle handle, Span<byte> buffer, ref int nameLen)
1151
return err == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(err);
1154
public static
SocketError
Bind(SafeSocketHandle handle, ProtocolType socketProtocolType, ReadOnlySpan<byte> buffer)
1158
return err == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(err);
1161
public static
SocketError
Listen(SafeSocketHandle handle, int backlog)
1164
return err == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(err);
1167
public static
SocketError
Accept(SafeSocketHandle listenSocket, Memory<byte> socketAddress, out int socketAddressLen, out SafeSocketHandle socket)
1172
SocketError
errorCode;
1181
errorCode =
SocketError
.WouldBlock;
1192
public static
SocketError
Connect(SafeSocketHandle handle, Memory<byte> socketAddress)
1199
SocketError
errorCode;
1208
return
SocketError
.WouldBlock;
1212
public static
SocketError
Send(SafeSocketHandle handle, IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out int bytesTransferred)
1223
SocketError
errorCode;
1228
public static
SocketError
Send(SafeSocketHandle handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, out int bytesTransferred)
1236
SocketError
errorCode;
1241
public static
SocketError
Send(SafeSocketHandle handle, ReadOnlySpan<byte> buffer, SocketFlags socketFlags, out int bytesTransferred)
1249
SocketError
errorCode;
1254
public static
SocketError
SendFile(SafeSocketHandle handle, SafeFileHandle fileHandle)
1265
SocketError
errorCode;
1267
return completed ? errorCode :
SocketError
.WouldBlock;
1270
public static
SocketError
SendTo(SafeSocketHandle handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Memory<byte> socketAddress, out int bytesTransferred)
1278
SocketError
errorCode;
1283
public static
SocketError
SendTo(SafeSocketHandle handle, ReadOnlySpan<byte> buffer, SocketFlags socketFlags, Memory<byte> socketAddress, out int bytesTransferred)
1291
SocketError
errorCode;
1296
public static
SocketError
Receive(SafeSocketHandle handle, IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out int bytesTransferred)
1298
SocketError
errorCode;
1307
errorCode =
SocketError
.WouldBlock;
1314
public static
SocketError
Receive(SafeSocketHandle handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, out int bytesTransferred)
1321
SocketError
errorCode;
1323
return completed ? errorCode :
SocketError
.WouldBlock;
1326
public static
SocketError
Receive(SafeSocketHandle handle, Span<byte> buffer, SocketFlags socketFlags, out int bytesTransferred)
1333
SocketError
errorCode;
1335
return completed ? errorCode :
SocketError
.WouldBlock;
1338
public static
SocketError
ReceiveMessageFrom(Socket socket, SafeSocketHandle handle, byte[] buffer, int offset, int count, ref SocketFlags socketFlags, SocketAddress socketAddress, out SocketAddress receiveAddress, out IPPacketInformation ipPacketInformation, out int bytesTransferred)
1345
SocketError
errorCode;
1354
errorCode =
SocketError
.WouldBlock;
1364
public static
SocketError
ReceiveMessageFrom(Socket socket, SafeSocketHandle handle, Span<byte> buffer, ref SocketFlags socketFlags, SocketAddress socketAddress, out SocketAddress receiveAddress, out IPPacketInformation ipPacketInformation, out int bytesTransferred)
1371
SocketError
errorCode;
1380
errorCode =
SocketError
.WouldBlock;
1389
public static
SocketError
ReceiveFrom(SafeSocketHandle handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Memory<byte> socketAddress, out int socketAddressLen, out int bytesTransferred)
1396
SocketError
errorCode;
1398
return completed ? errorCode :
SocketError
.WouldBlock;
1401
public static
SocketError
ReceiveFrom(SafeSocketHandle handle, Span<byte> buffer, SocketFlags socketFlags, Memory<byte> socketAddress, out int socketAddressLen, out int bytesTransferred)
1408
SocketError
errorCode;
1410
return completed ? errorCode :
SocketError
.WouldBlock;
1413
public static
SocketError
WindowsIoctl(SafeSocketHandle handle, int ioControlCode, byte[]? _ /*optionInValue*/, byte[]? optionOutValue, out int optionLength)
1435
return
SocketError
.Fault;
1439
SocketError
error = ioControlCode == FIONREAD ?
1442
if (error ==
SocketError
.Success)
1455
private static
SocketError
GetErrorAndTrackSetting(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, Interop.Error err)
1460
return
SocketError
.Success;
1465
public static unsafe
SocketError
SetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue)
1536
public static unsafe
SocketError
SetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue)
1545
public static unsafe
SocketError
SetRawSockOpt(SafeSocketHandle handle, int optionLevel, int optionName, ReadOnlySpan<byte> optionValue)
1559
return
SocketError
.Success;
1566
public static unsafe
SocketError
SetMulticastOption(SafeSocketHandle handle, SocketOptionName optionName, MulticastOption optionValue)
1589
public static unsafe
SocketError
SetIPv6MulticastOption(SafeSocketHandle handle, SocketOptionName optionName, IPv6MulticastOption optionValue)
1606
public static unsafe
SocketError
SetLingerOption(SafeSocketHandle handle, LingerOption optionValue)
1634
public static unsafe
SocketError
GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, out int optionValue)
1641
return
SocketError
.Success;
1646
return
SocketError
.Success;
1655
return getErrorError == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(getErrorError);
1674
return err == Interop.Error.SUCCESS ?
SocketError
.Success : GetSocketErrorForErrorCode(err);
1677
public static unsafe
SocketError
GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue, ref int optionLength)
1690
SocketError
returnError = GetSockOpt(handle, optionLevel, optionName, out outError);
1691
if (returnError ==
SocketError
.Success)
1712
return
SocketError
.Success;
1718
public static unsafe
SocketError
GetRawSockOpt(SafeSocketHandle handle, int optionLevel, int optionName, Span<byte> optionValue, ref int optionLength)
1730
return
SocketError
.Success;
1737
public static unsafe
SocketError
GetMulticastOption(SafeSocketHandle handle, SocketOptionName optionName, out MulticastOption? optionValue)
1759
return
SocketError
.Success;
1762
public static unsafe
SocketError
GetIPv6MulticastOption(SafeSocketHandle handle, SocketOptionName optionName, out IPv6MulticastOption? optionValue)
1779
return
SocketError
.Success;
1782
public static unsafe
SocketError
GetLingerOption(SafeSocketHandle handle, out LingerOption? optionValue)
1793
return
SocketError
.Success;
1796
public static
SocketError
Poll(SafeSocketHandle handle, int microseconds, SelectMode mode, out bool status)
1823
return
SocketError
.Success;
1826
public static unsafe
SocketError
Select(IList? checkRead, IList? checkWrite, IList? checkError, int microseconds)
1869
private static unsafe
SocketError
SelectViaSelect(IList? checkRead, IList? checkWrite, IList? checkError, int microseconds)
1918
return (
SocketError
)0;
1966
private static unsafe
SocketError
SelectViaPoll(
2014
return
SocketError
.Success;
2083
public static
SocketError
Shutdown(SafeSocketHandle handle, bool isConnected, bool isDisconnected, SocketShutdown how)
2089
return
SocketError
.Success;
2098
return
SocketError
.Success;
2104
private static
SocketError
SendFileAsync(SafeSocketHandle handle, SafeFileHandle fileHandle, long offset, long count, CancellationToken cancellationToken, Action<long,
SocketError
> callback)
2107
SocketError
socketError = handle.AsyncContext.SendFileAsync(fileHandle, offset, count, out bytesSent, callback, cancellationToken);
2108
if (socketError ==
SocketError
.Success)
2110
callback(bytesSent,
SocketError
.Success);
2116
Socket socket, TransmitFileOptions options, SendPacketsElement[] elements, SafeFileHandle[] fileHandles, CancellationToken cancellationToken, Action<long,
SocketError
> callback)
2118
SocketError
error =
SocketError
.Success;
2142
var tcs = new TaskCompletionSource<
SocketError
>();
2151
if (error ==
SocketError
.IOPending)
2155
if (error !=
SocketError
.Success)
2166
if (error !=
SocketError
.Success)
2181
exc is ArgumentException ?
SocketError
.InvalidArgument :
2182
exc is OperationCanceledException ?
SocketError
.OperationAborted :
2183
SocketError
.SocketError;
2191
internal static
SocketError
Disconnect(Socket socket, SafeSocketHandle handle, bool reuseSocket)
2198
SocketError
.Success;
2225
SocketError
errorCode = GetSockOpt(handle, SocketOptionLevel.Socket, SocketOptionName.Error, out int optionValue);
2226
if (errorCode !=
SocketError
.Success)
2231
success = (
SocketError
)optionValue ==
SocketError
.Success;
System\Net\Sockets\SocketsTelemetry.cs (27)
51
private void ConnectFailed(
SocketError
error, string? exceptionMessage)
75
private void AcceptFailed(
SocketError
error, string? exceptionMessage)
145
public void AfterConnect(
SocketError
error, Activity? activity, string? exceptionMessage = null)
155
bool connectPending = error is
SocketError
.WouldBlock or
SocketError
.InProgress;
159
if (error !=
SocketError
.Success && !connectPending)
168
if (error ==
SocketError
.Success)
200
public void AfterAccept(
SocketError
error, string? exceptionMessage = null)
202
if (error ==
SocketError
.Success)
241
private static string GetErrorType(
SocketError
socketError) => socketError switch
246
SocketError
.NetworkDown => "network_down",
247
SocketError
.AddressAlreadyInUse => "address_already_in_use",
248
SocketError
.Interrupted => "interrupted",
249
SocketError
.InProgress => "in_progress",
250
SocketError
.AlreadyInProgress => "already_in_progress",
251
SocketError
.AddressNotAvailable => "address_not_available",
252
SocketError
.AddressFamilyNotSupported => "address_family_not_supported",
253
SocketError
.ConnectionRefused => "connection_refused",
254
SocketError
.Fault => "fault",
255
SocketError
.InvalidArgument => "invalid_argument",
256
SocketError
.IsConnected => "is_connected",
257
SocketError
.NetworkUnreachable => "network_unreachable",
258
SocketError
.HostUnreachable => "host_unreachable",
259
SocketError
.NoBufferSpaceAvailable => "no_buffer_space_available",
260
SocketError
.TimedOut => "timed_out",
261
SocketError
.AccessDenied => "access_denied",
262
SocketError
.ProtocolType => "protocol_type",
System\Net\Sockets\UDPClient.cs (4)
425
throw new SocketException((int)
SocketError
.OperationNotSupported);
445
throw new SocketException((int)
SocketError
.OperationNotSupported);
513
throw new SocketException((int)
SocketError
.OperationNotSupported);
793
throw new SocketException((int)
SocketError
.NotConnected);
System.ServiceModel.Http (5)
System\ServiceModel\Channels\HttpChannelHelpers.cs (5)
125
SocketError
socketErrorCode = innerSocketException.SocketErrorCode;
128
case
SocketError
.TryAgain:
129
case
SocketError
.NoRecovery:
130
case
SocketError
.NoData:
131
case
SocketError
.HostNotFound:
System.ServiceModel.NetTcp (8)
System\ServiceModel\Channels\SocketAwaitableEventArgs.cs (8)
41
var
error = SocketError;
43
return error ==
SocketError
.Success
58
var
error = SocketError;
60
return error ==
SocketError
.Success
83
if (SocketError !=
SocketError
.Success)
95
if (SocketError !=
SocketError
.Success)
101
protected static SocketException CreateException(
SocketError
e)
109
SocketError ==
SocketError
.Success ? ValueTaskSourceStatus.Succeeded :
System.ServiceModel.UnixDomainSocket (8)
System\ServiceModel\Channels\SocketAwaitableEventArgs.cs (8)
41
var
error = SocketError;
43
return error ==
SocketError
.Success
58
var
error = SocketError;
60
return error ==
SocketError
.Success
83
if (SocketError !=
SocketError
.Success)
95
if (SocketError !=
SocketError
.Success)
101
protected static SocketException CreateException(
SocketError
e)
109
SocketError ==
SocketError
.Success ? ValueTaskSourceStatus.Succeeded :