为什么System.Net.ServicePoint.ConnectionLimit用途“7FFFFFFF”(Int32.MaxValue / 2147483647),当客户端连接到'localhost'的服务? [英] Why System.Net.ServicePoint.ConnectionLimit uses '7FFFFFFF' (Int32.MaxValue/2147483647) when a client connects to a service on 'localhost'?

查看:234
本文介绍了为什么System.Net.ServicePoint.ConnectionLimit用途“7FFFFFFF”(Int32.MaxValue / 2147483647),当客户端连接到'localhost'的服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么System.Net.ServicePoint.ConnectionLimit使用7FFFFFFF(Int32.MaxValue / 2147483647)当客户端连接到服务上的本地主机,而它决定使用'2'作为默认该服务是否在远程机器上运行?

Why System.Net.ServicePoint.ConnectionLimit uses '7FFFFFFF' (Int32.MaxValue/2147483647) when a client connects to a service on 'localhost', whereas it decide to use '2' as default if the service is running on remote machine?

起初,我想如果servicepoint.connectionlimit没有设置将被ServicePointManager.DefaultConnectionLimit。然而,我才意识到(一旦我得到了来自客户的问题),其Int32.MaxValue / 2147483647。

Initially I thought it will be ServicePointManager.DefaultConnectionLimit if servicepoint.connectionlimit is not set. However, I just realized (once I got an issue from customer), that its Int32.MaxValue/2147483647.

我已经做了一些研究(详情请参考下面的链接),但是我找不到为什么使用它来int32.maxvalue。那种我可以推测它可能有更好的表现作为输入请求和响应消息都不会跨越边界。

I have done some research (for details please refer to below links), however I couldn't find out why it uses to int32.maxvalue. I can kind of conjecture its probably for better performance as the input requests and response messages are not going across boundary.

我的问题(S):

  1. 为什么如果Int32.MaxValue服务正在运行的本地主机? (任何的英文解释;)的code段,我从反光抄也很大 - 因为我种猜测的意图 - 但不了解code完全:))
  2. 在我理解其对PERF - 而是从2(默认值)为int32.maxvalue的声音舒展给我。换句话说,为什么它确定,只要申请都不会通过网络打开多个TCP连接。 (换句话说 - 为什么默认int32.maxvalue - 没有它有副作用的影响)
  1. Why Int32.MaxValue if the service is running on 'localhost'? (any explanation in English ;) of the code snippet I copied from reflector is also great - as I kind of conjectured the intentions - but didn't understand the code totally :))
  2. I understand its for perf - but from '2' (default) to 'int32.maxvalue' sounds stretch to me. In other words why is it ok to open as many TCP connections as long as the requests are not going across network. (in other words - why default to int32.maxvalue - doesn't it have side affects)

与此相关的一些有用的链接:

<一个href="http://stackoverflow.com/questions/22800216/how-and-where-the-tcp-connection-has-been-created-in-httpwebrequest-and-how-is">How并在TCP连接已在HttpWebRequest的创建,以及它是如何涉及到服务点?

<一个href="http://blogs.microsoft.co.il/idof/2011/06/20/servicepointmanagerdefaultconnectionlimit-2-depends/" rel="nofollow">http://blogs.microsoft.co.il/idof/2011/06/20/servicepointmanagerdefaultconnectionlimit-2-depends/

<一个href="http://msdn.microsoft.com/en-us/library/system.net.servicepoint.connectionlimit(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.net.servicepoint.connectionlimit(v=vs.110).aspx

http://arnosoftwaredev.blogspot.com/2006/09/net-20-httpwebrequestkeepalive-and.html

code从反射段

  public int ConnectionLimit
        {
            get
            {
                if ((!this.m_UserChangedLimit && (this.m_IPAddressInfoList == null)) && (this.m_HostLoopbackGuess == TriState.Unspecified))
                {
                    lock (this)
                    {
                        if ((!this.m_UserChangedLimit && (this.m_IPAddressInfoList == null)) && (this.m_HostLoopbackGuess == TriState.Unspecified))
                        {
                            IPAddress address = null;
                            if (IPAddress.TryParse(this.m_Host, out address))
                            {
                                this.m_HostLoopbackGuess = IsAddressListLoopback(new IPAddress[] { address }) ? TriState.True : TriState.False;
                            }
                            else
                            {
                                this.m_HostLoopbackGuess = NclUtilities.GuessWhetherHostIsLoopback(this.m_Host) ? TriState.True : TriState.False;
                            }
                        }
                    }
                }
                if (!this.m_UserChangedLimit && !((this.m_IPAddressInfoList == null) ? (this.m_HostLoopbackGuess != TriState.True) : !this.m_IPAddressesAreLoopback))
                {
                    return 0x7fffffff;
                }
                return this.m_ConnectionLimit;
            }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentOutOfRangeException("value");
                }
                if (!this.m_UserChangedLimit || (this.m_ConnectionLimit != value))
                {
                    lock (this)
                    {
                        if (!this.m_UserChangedLimit || (this.m_ConnectionLimit != value))
                        {
                            this.m_ConnectionLimit = value;
                            this.m_UserChangedLimit = true;
                            this.ResolveConnectionLimit();
                        }
                    }
                }
            }
        }

问候,

推荐答案

Int32.maxvalue只是一个占位符,没有限制。您应该可以,因为你需要创建尽可能多的连接到自己。

Int32.maxvalue is just a placeholder for no limit. You should be able to create as many connections to yourself as you need to.

在code你基本上粘贴只检查是否已经连接到环回地址或不是,如果你是,返回MAXINT,如果你不是,返回servicepoint.connectionlimit(2默认值,但你可以改变它)

The code you pasted basically just checks whether you are connecting to the loopback address or not, and if you are, returns maxint, if you are not, returns the value of servicepoint.connectionlimit (2 by default, but you can change it)

这篇关于为什么System.Net.ServicePoint.ConnectionLimit用途“7FFFFFFF”(Int32.MaxValue / 2147483647),当客户端连接到'localhost'的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆