示例#1
0
        //public const string CONFIG_LOGTYPE_ATTR = "log-type";
        //public const string CONFIG_DEFAULT_TIMEOUT_MS_ATTR = "default-timeout-ms";



        /// <summary>
        /// Ensures that ServicePointManager class gets configured via the ServicePointManagerConfigurator instance.
        /// ServicePointManager is .NET-provided class with static methods which configure global Web call/service point properties
        /// such as timeouts and keep-alive.
        /// </summary>
        public static ServicePointManagerConfigurator GetServicePointManagerConfigurator(this IApplication app) =>
        app.NonNull(nameof(app)).Singletons.GetOrCreate <ServicePointManagerConfigurator>(() =>
        {
            var result = new ServicePointManagerConfigurator(app);
            ((IConfigurable)result).Configure(app.ConfigRoot[CONFIG_WEBSETTINGS_SECTION]);
            return(result);
        }).instance;
            internal ServicePointConfigurator(ServicePointManagerConfigurator manager, ServicePoint sp, IConfigSectionNode node)
            {
                this.Manager               = manager;
                this.ServicePoint          = sp;
                sp.BindIPEndPointDelegate += bindIPEndPoint;
                ConfigAttribute.Apply(this, node);

                if (node.AttrByName(CONFIG_TCP_KEEPALIVE_ENABLED_ATTR).ValueAsBool())
                {
                    sp.SetTcpKeepAlive(
                        true,
                        node.AttrByName(CONFIG_TCP_KEEPALIVE_TIME_MS_ATTR).ValueAsInt(),
                        node.AttrByName(CONFIG_TCP_KEEPALIVE_INTERVAL_MS_ATTR).ValueAsInt());
                }
            }