< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 42
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
CacheCredential(...)0%880%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/Common/src/System/Net/Security/SSPIHandleCache.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.Threading;
 5
 6namespace System.Net.Security
 7{
 8    //
 9    // Implements delayed SSPI handle release:
 10    // finalizable objects though the handles are kept alive until being pushed out by the newly incoming ones.
 11    //
 12    internal static class SSPIHandleCache
 13    {
 14        private const int MaxCacheSize = 0x1F;  // must a (power of 2) - 1
 015        private static readonly SafeCredentialReference?[] s_cacheSlots = new SafeCredentialReference[MaxCacheSize + 1];
 016        private static int s_current = -1;
 17
 18        internal static void CacheCredential(SafeFreeCredentials newHandle)
 019        {
 20            try
 021            {
 022                SafeCredentialReference? newRef = SafeCredentialReference.CreateReference(newHandle);
 023                if (newRef == null)
 024                {
 025                    return;
 26                }
 27
 028                int index = Interlocked.Increment(ref s_current) & MaxCacheSize;
 29
 030                Interlocked.Exchange(ref s_cacheSlots[index], newRef)?.Dispose();
 031            }
 032            catch (Exception e)
 033            {
 034                if (NetEventSource.Log.IsEnabled() && !ExceptionCheck.IsFatal(e))
 035                {
 036                    NetEventSource.Error(null, $"Attempted to throw: {e}");
 037                }
 038            }
 039        }
 40    }
 41}
 42