| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Runtime; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | public class ConnectionPoolSettings |
| | | 10 | | { |
| | | 11 | | private TimeSpan _idleTimeout; |
| | | 12 | | private int _maxOutboundConnectionsPerEndpoint; |
| | | 13 | | private TimeSpan _channelInitializationTimeout; |
| | | 14 | | |
| | 200 | 15 | | internal protected ConnectionPoolSettings() |
| | | 16 | | { |
| | 200 | 17 | | _channelInitializationTimeout = ConnectionOrientedTransportDefaults.ChannelInitializationTimeout; |
| | 200 | 18 | | _idleTimeout = ConnectionOrientedTransportDefaults.IdleTimeout; |
| | 200 | 19 | | _maxOutboundConnectionsPerEndpoint = ConnectionOrientedTransportDefaults.MaxOutboundConnectionsPerEndpoint; |
| | 200 | 20 | | } |
| | | 21 | | |
| | 1920 | 22 | | internal protected ConnectionPoolSettings(ConnectionPoolSettings other) |
| | | 23 | | { |
| | 1920 | 24 | | _channelInitializationTimeout = other._channelInitializationTimeout; |
| | 1920 | 25 | | _idleTimeout = other._idleTimeout; |
| | 1920 | 26 | | _maxOutboundConnectionsPerEndpoint = other._maxOutboundConnectionsPerEndpoint; |
| | 1920 | 27 | | } |
| | | 28 | | |
| | | 29 | | public TimeSpan ChannelInitializationTimeout |
| | | 30 | | { |
| | 79 | 31 | | get => _channelInitializationTimeout; |
| | | 32 | | set |
| | | 33 | | { |
| | 3 | 34 | | if (value <= TimeSpan.Zero) |
| | | 35 | | { |
| | 0 | 36 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 37 | | SRCommon.TimeSpanMustBeGreaterThanTimeSpanZero)); |
| | | 38 | | } |
| | | 39 | | |
| | 3 | 40 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 41 | | { |
| | 0 | 42 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 43 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 44 | | } |
| | | 45 | | |
| | 3 | 46 | | _channelInitializationTimeout = value; |
| | 3 | 47 | | } |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public TimeSpan IdleTimeout |
| | | 51 | | { |
| | 106 | 52 | | get { return _idleTimeout; } |
| | | 53 | | set |
| | | 54 | | { |
| | 2 | 55 | | if (value < TimeSpan.Zero) |
| | | 56 | | { |
| | 0 | 57 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(Idl |
| | 0 | 58 | | SRCommon.SFxTimeoutOutOfRange0)); |
| | | 59 | | } |
| | | 60 | | |
| | 2 | 61 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 62 | | { |
| | 0 | 63 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(Idl |
| | 0 | 64 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 65 | | } |
| | | 66 | | |
| | 2 | 67 | | _idleTimeout = value; |
| | 2 | 68 | | } |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | public int MaxOutboundConnectionsPerEndpoint |
| | | 72 | | { |
| | 72 | 73 | | get { return _maxOutboundConnectionsPerEndpoint; } |
| | | 74 | | set |
| | | 75 | | { |
| | 2 | 76 | | if (value < 0) |
| | | 77 | | { |
| | 0 | 78 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(Max |
| | 0 | 79 | | SRCommon.ValueMustBeNonNegative)); |
| | | 80 | | } |
| | | 81 | | |
| | 2 | 82 | | _maxOutboundConnectionsPerEndpoint = value; |
| | 2 | 83 | | } |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | public bool IsMatch(ConnectionPoolSettings connectionPool) |
| | | 87 | | { |
| | 0 | 88 | | if (_idleTimeout != connectionPool._idleTimeout) |
| | | 89 | | { |
| | 0 | 90 | | return false; |
| | | 91 | | } |
| | | 92 | | |
| | 0 | 93 | | if (_maxOutboundConnectionsPerEndpoint != connectionPool._maxOutboundConnectionsPerEndpoint) |
| | | 94 | | { |
| | 0 | 95 | | return false; |
| | | 96 | | } |
| | | 97 | | |
| | 0 | 98 | | if (_channelInitializationTimeout != connectionPool._channelInitializationTimeout) |
| | | 99 | | { |
| | 0 | 100 | | return false; |
| | | 101 | | } |
| | | 102 | | |
| | 0 | 103 | | return true; |
| | | 104 | | } |
| | | 105 | | } |
| | | 106 | | } |