Пример #1
0
        public SocketTuner(SocketsTransportSettings settings, ILog log)
        {
            this.log = log;

            arpWarmupEnabled = settings.ArpCacheWarmupEnabled && RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
            keepAliveEnabled = settings.TcpKeepAliveEnabled && RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
            keepAliveValues  = keepAliveEnabled ? GetKeepAliveValues(settings) : null;
        }
 private static GlobalCacheKey CreateKey(SocketsTransportSettings settings, TimeSpan?connectionTimeout)
 => new GlobalCacheKey(
     settings.Proxy,
     settings.AllowAutoRedirect,
     connectionTimeout ?? Timeout.InfiniteTimeSpan,
     settings.ConnectionIdleTimeout,
     settings.ConnectionLifetime,
     settings.MaxConnectionsPerEndpoint,
     settings.CustomTuning);
Пример #3
0
 private static GlobalCacheKey CreateKey(SocketsTransportSettings settings, TimeSpan?connectionTimeout)
 => new GlobalCacheKey(
     settings.Proxy,
     settings.AllowAutoRedirect,
     connectionTimeout ?? Timeout.InfiniteTimeSpan,
     settings.ConnectionIdleTimeout,
     settings.ConnectionLifetime,
     settings.MaxConnectionsPerEndpoint,
     settings.ClientCertificates,
     settings.RemoteCertificateValidationCallback);
Пример #4
0
        /// <inheritdoc cref="SocketsHttpHandler" />
        public SocketsTransport([NotNull] SocketsTransportSettings settings, [NotNull] ILog log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = log ?? throw new ArgumentNullException(nameof(log));

            handlerProvider = new SocketsHandlerProvider(settings);
            timeoutProvider = new TimeoutProvider(settings.RequestAbortTimeout, this.log);
            errorHandler    = new ErrorHandler(this.log);
            socketTuner     = new SocketTuner(settings, this.log);
            bodyReader      = new BodyReader(
                settings.BufferFactory,
                len => settings.UseResponseStreaming(len),
                () => settings.MaxResponseBodySize,
                this.log);
        }
Пример #5
0
        private static byte[] GetKeepAliveValues(SocketsTransportSettings settings)
        {
            var tcpKeepAliveTime     = (int)settings.TcpKeepAliveTime.TotalMilliseconds;
            var tcpKeepAliveInterval = (int)settings.TcpKeepAliveInterval.TotalMilliseconds;

            return(new byte[]
            {
                1,
                0,
                0,
                0,
                (byte)(tcpKeepAliveTime & byte.MaxValue),
                (byte)((tcpKeepAliveTime >> 8) & byte.MaxValue),
                (byte)((tcpKeepAliveTime >> 16) & byte.MaxValue),
                (byte)((tcpKeepAliveTime >> 24) & byte.MaxValue),
                (byte)(tcpKeepAliveInterval & byte.MaxValue),
                (byte)((tcpKeepAliveInterval >> 8) & byte.MaxValue),
                (byte)((tcpKeepAliveInterval >> 16) & byte.MaxValue),
                (byte)((tcpKeepAliveInterval >> 24) & byte.MaxValue)
            });
        }
Пример #6
0
 /// <summary>
 /// Initialiazes configuration transport with a <see cref="SocketsTransport"/> with given settings.
 /// </summary>
 public static void SetupSocketTransport(this IClusterClientConfiguration self, SocketsTransportSettings settings)
 {
     self.Transport = new SocketsTransport(settings, self.Log);
 }
 public SocketsHandlerProvider(SocketsTransportSettings settings)
 {
     localCache        = new RecyclingBoundedCache <TimeSpan, SocketsHttpHandler>(LocalCacheCapacity);
     localCacheFactory = timeout => globalCache.Obtain(CreateKey(settings, timeout), CreateHandler);
 }