< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 94
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: .ctor(...)100%110%
File 1: .ctor(...)100%110%
File 1: .ctor(...)100%110%
File 1: .ctor(...)100%110%
File 1: .ctor(...)0%220%
File 2: .ctor()100%110%
File 2: GetNativeErrorForSocketError(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.ComponentModel;
 5using System.Runtime.Serialization;
 6
 7namespace System.Net.Sockets
 8{
 9    /// <summary>Provides socket exceptions to the application.</summary>
 10    [Serializable]
 11    [System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5
 12    public partial class SocketException : Win32Exception
 13    {
 14        /// <summary>The SocketError or Int32 specified when constructing the exception.</summary>
 15        /// <remarks>Based on platform, this may or may not be the same as the underlying NativeErrorCode.</remarks>
 16        private readonly SocketError _errorCode;
 17
 18        /// <summary>Creates a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the speci
 019        public SocketException(int errorCode) : this((SocketError)errorCode)
 020        {
 21            // NOTE: SocketException(SocketError) isn't exposed publicly.  As a result, code with a SocketError calls
 22            // this ctor, e.g.
 23            //     SocketError error = ...;
 24            //     throw new SocketException((int)error);
 25            // That means we need to assume the errorCode is a SocketError value, rather than a platform-specific error 
 26            // Hence, no translation on the supplied code.  This does mean on Unix there's a difference between:
 27            //     new SocketException(); // will treat the last error as a native error code and translate it appropria
 28            // and:
 29            //     new SocketException(Marshal.GetLastPInvokeError()); // will treat the last error as a SocketError, in
 30            // but that's the least bad option right now.
 031        }
 32
 33        /// <summary>Initializes a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the s
 034        public SocketException(int errorCode, string? message) : this((SocketError)errorCode, message)
 035        {
 036        }
 37
 38        /// <summary>Creates a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the speci
 039        internal SocketException(SocketError socketError) : base(GetNativeErrorForSocketError(socketError))
 040        {
 041            _errorCode = socketError;
 042        }
 43
 44        /// <summary>Initializes a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the s
 045        internal SocketException(SocketError socketError, string? message) : base(GetNativeErrorForSocketError(socketErr
 046        {
 047            _errorCode = socketError;
 048        }
 49
 050        public override string Message => base.Message;
 51
 052        public SocketError SocketErrorCode => _errorCode;
 53
 54        [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma
 55        [EditorBrowsable(EditorBrowsableState.Never)]
 56        protected SocketException(SerializationInfo serializationInfo, StreamingContext streamingContext)
 057            : base(serializationInfo, streamingContext)
 058        {
 059            if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"{NativeErrorCode}:{Message}");
 060        }
 61
 062        public override int ErrorCode => base.NativeErrorCode;
 63    }
 64}
 65

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Primitives/src/System/Net/SocketException.Windows.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.ComponentModel;
 5using System.Runtime.InteropServices;
 6
 7namespace System.Net.Sockets
 8{
 9    public partial class SocketException : Win32Exception
 10    {
 11        /// <summary>Creates a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the defau
 012        public SocketException() : this(Marshal.GetLastPInvokeError())
 013        {
 014        }
 15
 16        internal SocketException(SocketError errorCode, uint _ /*platformError*/)
 17            : this(errorCode)
 18        {
 19            // platformError is unused on Windows. It's the same value as errorCode.
 20        }
 21
 22        private static int GetNativeErrorForSocketError(SocketError error)
 023        {
 24            // SocketError values map directly to Win32 error codes
 025            return (int)error;
 026        }
 27    }
 28}
 29