public SetTcpKeepAlive ( bool enabled, int keepAliveTime, int keepAliveInterval ) : void | ||
enabled | bool | |
keepAliveTime | int | |
keepAliveInterval | int | |
Résultat | void |
public static ServicePoint FindServicePoint(Uri address, IWebProxy proxy) { if (address == null) { throw new ArgumentNullException("address"); } var origAddress = new Uri(address.Scheme + "://" + address.Authority); bool usesProxy = false; bool useConnect = false; if (proxy != null && !proxy.IsBypassed(address)) { usesProxy = true; bool isSecure = address.Scheme == "https"; address = proxy.GetProxy(address); if (address.Scheme != "http") { throw new NotSupportedException("Proxy scheme not supported."); } if (isSecure && address.Scheme == "http") { useConnect = true; } } address = new Uri(address.Scheme + "://" + address.Authority); var key = new SPKey(origAddress, usesProxy ? address : null, useConnect); lock (servicePoints) { if (servicePoints.TryGetValue(key, out var sp)) { return(sp); } if (maxServicePoints > 0 && servicePoints.Count >= maxServicePoints) { throw new InvalidOperationException("maximum number of service points reached"); } int limit; #if MOBILE limit = defaultConnectionLimit; #else string addr = address.ToString(); limit = (int)manager.GetMaxConnections(addr); #endif sp = new ServicePoint(key, address, limit, maxServicePointIdleTime); sp.Expect100Continue = expectContinue; sp.UseNagleAlgorithm = useNagle; sp.UsesProxy = usesProxy; sp.UseConnect = useConnect; sp.SetTcpKeepAlive(tcp_keepalive, tcp_keepalive_time, tcp_keepalive_interval); return(servicePoints.GetOrAdd(key, sp)); } }
public Worker(ParsingType type, PageParser parser, EventHandler onPageDownloadingComplete = null) { _type = type; _parser = parser; _address = LocaleMgr.GetAddress(parser.Locale); ServicePointManager.DefaultConnectionLimit = SemaphoreCount * 10; { _service = ServicePointManager.FindServicePoint(_address); _service.SetTcpKeepAlive(true, KeepAliveTime, KeepAliveTime); } _address = new Uri(_address, parser.Address); _semaphore = new SemaphoreSlim(SemaphoreCount, SemaphoreCount); _badIds = new ConcurrentQueue<uint>(); PageDownloadingComplete += onPageDownloadingComplete; }
public Worker(ParsingType type, PageParser parser, EventHandler onPageDownloadingComplete = null) { m_type = type; m_parser = parser; m_address = new Uri(string.Format("http://{0}.wowhead.com/", parser.Locale.GetLocalePrefix())); ServicePointManager.DefaultConnectionLimit = SemaphoreCount * 10; { m_service = ServicePointManager.FindServicePoint(m_address); m_service.SetTcpKeepAlive(true, KeepAliveTime, KeepAliveTime); } m_semaphore = new SemaphoreSlim(SemaphoreCount, SemaphoreCount); m_storeUnprocessedIds = m_type == ParsingType.TypeByList || m_type == ParsingType.TypeByWoWHeadFilter; if (m_storeUnprocessedIds) m_badIds = new Queue<uint>(); PageDownloadingComplete += onPageDownloadingComplete; }
public static ServicePoint FindServicePoint (Uri address, IWebProxy proxy) { if (address == null) throw new ArgumentNullException ("address"); RecycleServicePoints (); bool usesProxy = false; bool useConnect = false; if (proxy != null && !proxy.IsBypassed(address)) { usesProxy = true; bool isSecure = address.Scheme == "https"; address = proxy.GetProxy (address); if (address.Scheme != "http" && !isSecure) throw new NotSupportedException ("Proxy scheme not supported."); if (isSecure && address.Scheme == "http") useConnect = true; } address = new Uri (address.Scheme + "://" + address.Authority); ServicePoint sp = null; lock (servicePoints) { SPKey key = new SPKey (address, useConnect); sp = servicePoints [key] as ServicePoint; if (sp != null) return sp; if (maxServicePoints > 0 && servicePoints.Count >= maxServicePoints) throw new InvalidOperationException ("maximum number of service points reached"); string addr = address.ToString (); #if NET_2_1 int limit = defaultConnectionLimit; #else int limit = (int) manager.GetMaxConnections (addr); #endif sp = new ServicePoint (address, limit, maxServicePointIdleTime); sp.Expect100Continue = expectContinue; sp.UseNagleAlgorithm = useNagle; sp.UsesProxy = usesProxy; sp.UseConnect = useConnect; sp.SetTcpKeepAlive (tcp_keepalive, tcp_keepalive_time, tcp_keepalive_interval); servicePoints.Add (key, sp); } return sp; }
internal ServicePointConfigurator(ServicePoint sp, IConfigSectionNode node) { 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()); } }
public void Parser(PageParser parser) { if (parser == null) throw new ArgumentNullException("parser"); _parser = parser; _address = new Uri(string.Format("http://{0}wowhead.com/", _locales[parser.Locale])); ServicePointManager.DefaultConnectionLimit = SemaphoreCount * 10; _service = ServicePointManager.FindServicePoint(_address); { _service.SetTcpKeepAlive(true, 100000, 100000); } _address = new Uri(_address, parser.Address); }