Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么System.Net.ServicePoint.ConnectionLimit使用';7FFFFFFF';(Int32.MaxValue/2147483647)当客户端连接到';本地主机';?_C#_Asp.net_.net_Servicepoint - Fatal编程技术网

C# 为什么System.Net.ServicePoint.ConnectionLimit使用';7FFFFFFF';(Int32.MaxValue/2147483647)当客户端连接到';本地主机';?

C# 为什么System.Net.ServicePoint.ConnectionLimit使用';7FFFFFFF';(Int32.MaxValue/2147483647)当客户端连接到';本地主机';?,c#,asp.net,.net,servicepoint,C#,Asp.net,.net,Servicepoint,为什么System.Net.ServicePoint.ConnectionLimit在客户端连接到'localhost'上的服务时使用'7FFFFFFF'(Int32.MaxValue/2147483647),而如果服务在远程计算机上运行,它决定使用'2'作为默认值 最初,我认为如果未设置servicepoint.connectionlimit,它将是ServicePointManager.DefaultConnectionLimit。然而,我刚刚意识到(当我收到客户的问题时),它是Int32.

为什么System.Net.ServicePoint.ConnectionLimit在客户端连接到'localhost'上的服务时使用'7FFFFFFF'(Int32.MaxValue/2147483647),而如果服务在远程计算机上运行,它决定使用'2'作为默认值

最初,我认为如果未设置servicepoint.connectionlimit,它将是ServicePointManager.DefaultConnectionLimit。然而,我刚刚意识到(当我收到客户的问题时),它是Int32.MaxValue/2147483647

我做了一些研究(有关详细信息,请参阅下面的链接),但我不知道为什么它使用int32.maxvalue。我可以推测它可能会有更好的性能,因为输入请求和响应消息不会越界

我的问题:

  • 如果服务在“本地主机”上运行,为什么选择Int32.MaxValue? (任何英文解释;)我从reflector复制的代码片段也很好——正如我猜测的那样——但没有完全理解代码:)
  • 我理解它的性能-但从'2'(默认值)到'int32.maxvalue'对我来说听起来很难理解。换句话说,为什么只要请求不通过网络,就可以打开尽可能多的TCP连接。 (换句话说——为什么默认为int32.maxvalue——它没有副作用)
  • 与此相关的一些有用链接:

    反射器中的代码片段

      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();
                            }
                        }
                    }
                }
            }
    
    public int ConnectionLimit
    {
    得到
    {
    if((!this.m_UserChangedLimit&&(this.m_ipaddressinfo==null))&&(this.m_HostLoopbackGuess==TriState.Unspecified))
    {
    锁(这个)
    {
    if((!this.m_UserChangedLimit&&(this.m_ipaddressinfo==null))&&(this.m_HostLoopbackGuess==TriState.Unspecified))
    {
    IP地址=空;
    if(IPAddress.TryParse(此.m_主机,输出地址))
    {
    this.m_HostLoopbackGuess=IsAddressListLoopback(新IPAddress[]{address})?TriState.True:TriState.False;
    }
    其他的
    {
    this.m_HostLoopbackGuess=NclUtilities.gusticestherhostisloopback(this.m_Host)?TriState.True:TriState.False;
    }
    }
    }
    }
    如果(!this.m_UserChangedLimit&&!((this.m_ipaddressinfo==null)?(this.m_HostLoopbackGuess!=TriState.True):!this.m_IPAddressesAreLoopback))
    {
    返回0x7fffffff;
    }
    返回此.m_连接限制;
    }
    设置
    {
    
    if(valueInt32.maxvalue只是一个无限制的占位符。您应该能够根据需要为自己创建尽可能多的连接


    粘贴的代码基本上只是检查是否连接到环回地址,如果连接到环回地址,则返回maxint,如果不是,则返回servicepoint.connectionlimit的值(默认情况下为2,但可以更改)

    是的,我明白了。我的问题是,为什么它决定只为本地主机使用一些占位符,而对于远程主机,它默认为“ServicePointManager.DefaultConnectionLimit”,以防用户不更改servicepoint.connectionlimit。它可能是Microsoft认为“2”对于本地主机来说太低了(对于远程主机来说也应该是低的),决定只更新“localhost”-没有好的默认值可供使用,并由用户自行决定,因为它会根据用例的不同而变化?这只是猜测,但在我的情况下,当我第一次使用这个类时,我首先在本地进行了测试,然后在尝试访问远程时发现了connectionlimit问题。因此它迫使您想一想您希望在正确的时间允许多少连接,而不是在实例化时要求connectionlimit,在实例化时,我可能会不假思索地输入任何值