/
TcpConnectionPoolSettings.cs
127 lines (108 loc) · 3.99 KB
/
TcpConnectionPoolSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime;
namespace System.ServiceModel.Channels
{
public sealed class TcpConnectionPoolSettings
{
private string _groupName;
private TimeSpan _idleTimeout;
private TimeSpan _leaseTimeout;
private int _maxOutboundConnectionsPerEndpoint;
internal TcpConnectionPoolSettings()
{
_groupName = ConnectionOrientedTransportDefaults.ConnectionPoolGroupName;
_idleTimeout = ConnectionOrientedTransportDefaults.IdleTimeout;
_leaseTimeout = TcpTransportDefaults.ConnectionLeaseTimeout;
_maxOutboundConnectionsPerEndpoint = ConnectionOrientedTransportDefaults.MaxOutboundConnectionsPerEndpoint;
}
internal TcpConnectionPoolSettings(TcpConnectionPoolSettings tcp)
{
_groupName = tcp._groupName;
_idleTimeout = tcp._idleTimeout;
_leaseTimeout = tcp._leaseTimeout;
_maxOutboundConnectionsPerEndpoint = tcp._maxOutboundConnectionsPerEndpoint;
}
public string GroupName
{
get { return _groupName; }
set
{
_groupName = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
}
}
public TimeSpan IdleTimeout
{
get { return _idleTimeout; }
set
{
if (value < TimeSpan.Zero)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(value), value,
SR.SFxTimeoutOutOfRange0));
}
if (TimeoutHelper.IsTooLarge(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(value), value,
SR.SFxTimeoutOutOfRangeTooBig));
}
_idleTimeout = value;
}
}
public TimeSpan LeaseTimeout
{
get { return _leaseTimeout; }
set
{
if (value < TimeSpan.Zero)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(value), value,
SR.SFxTimeoutOutOfRange0));
}
if (TimeoutHelper.IsTooLarge(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(value), value,
SR.SFxTimeoutOutOfRangeTooBig));
}
_leaseTimeout = value;
}
}
public int MaxOutboundConnectionsPerEndpoint
{
get { return _maxOutboundConnectionsPerEndpoint; }
set
{
if (value < 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(value), value,
SR.ValueMustBeNonNegative));
}
_maxOutboundConnectionsPerEndpoint = value;
}
}
internal TcpConnectionPoolSettings Clone()
{
return new TcpConnectionPoolSettings(this);
}
internal bool IsMatch(TcpConnectionPoolSettings tcp)
{
if (_groupName != tcp._groupName)
{
return false;
}
if (_idleTimeout != tcp._idleTimeout)
{
return false;
}
if (_leaseTimeout != tcp._leaseTimeout)
{
return false;
}
if (_maxOutboundConnectionsPerEndpoint != tcp._maxOutboundConnectionsPerEndpoint)
{
return false;
}
return true;
}
}
}