| | | 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 System.Security.Authentication.ExtendedProtection; |
| | | 6 | | using CoreWCF.Configuration; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public class TcpTransportBindingElement : ConnectionOrientedTransportBindingElement |
| | | 11 | | { |
| | | 12 | | private int _listenBacklog; |
| | | 13 | | private TcpConnectionPoolSettings _connectionPoolSettings; |
| | | 14 | | private ExtendedProtectionPolicy _extendedProtectionPolicy; |
| | | 15 | | |
| | 120 | 16 | | public TcpTransportBindingElement() : base() |
| | | 17 | | { |
| | 120 | 18 | | _listenBacklog = TcpTransportDefaults.GetListenBacklog(); |
| | 120 | 19 | | _connectionPoolSettings = new TcpConnectionPoolSettings(); |
| | 120 | 20 | | _extendedProtectionPolicy = ChannelBindingUtility.DefaultPolicy; |
| | 120 | 21 | | } |
| | 1849 | 22 | | protected TcpTransportBindingElement(TcpTransportBindingElement elementToBeCloned) : base(elementToBeCloned) |
| | | 23 | | { |
| | 1849 | 24 | | _listenBacklog = elementToBeCloned._listenBacklog; |
| | 1849 | 25 | | _connectionPoolSettings = elementToBeCloned._connectionPoolSettings.Clone(); |
| | 1849 | 26 | | _extendedProtectionPolicy = elementToBeCloned.ExtendedProtectionPolicy; |
| | 1849 | 27 | | } |
| | | 28 | | |
| | | 29 | | [Obsolete("ConnectionPoolSettings now set on TcpListenOptions which is modifiable via a configuration delegate w |
| | 4 | 30 | | public TcpConnectionPoolSettings ConnectionPoolSettings => _connectionPoolSettings; |
| | | 31 | | |
| | | 32 | | public int ListenBacklog |
| | | 33 | | { |
| | | 34 | | get |
| | | 35 | | { |
| | 1 | 36 | | return _listenBacklog; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | set |
| | | 40 | | { |
| | 1 | 41 | | if (value <= 0) |
| | | 42 | | { |
| | 0 | 43 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 44 | | SRCommon.ValueMustBePositive)); |
| | | 45 | | } |
| | | 46 | | |
| | 1 | 47 | | _listenBacklog = value; |
| | 1 | 48 | | } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public override string Scheme |
| | | 52 | | { |
| | 550 | 53 | | get { return "net.tcp"; } |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | public ExtendedProtectionPolicy ExtendedProtectionPolicy |
| | | 57 | | { |
| | | 58 | | get |
| | | 59 | | { |
| | 1853 | 60 | | return _extendedProtectionPolicy; |
| | | 61 | | } |
| | | 62 | | set |
| | | 63 | | { |
| | 1124 | 64 | | if (value == null) |
| | | 65 | | { |
| | 0 | 66 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 67 | | } |
| | | 68 | | |
| | 1124 | 69 | | if (value.PolicyEnforcement == PolicyEnforcement.Always && |
| | 1124 | 70 | | !ExtendedProtectionPolicy.OSSupportsExtendedProtection) |
| | | 71 | | { |
| | 0 | 72 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 73 | | new PlatformNotSupportedException(SR.ExtendedProtectionNotSupported)); |
| | | 74 | | } |
| | | 75 | | |
| | 1124 | 76 | | _extendedProtectionPolicy = value; |
| | 1124 | 77 | | } |
| | | 78 | | } |
| | | 79 | | |
| | 1 | 80 | | protected override string WsdlTransportUri => "http://schemas.microsoft.com/soap/tcp"; |
| | | 81 | | |
| | | 82 | | public override BindingElement Clone() |
| | | 83 | | { |
| | 1849 | 84 | | return new TcpTransportBindingElement(this); |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | public override T GetProperty<T>(BindingContext context) |
| | | 88 | | { |
| | 338 | 89 | | if (context == null) |
| | | 90 | | { |
| | 0 | 91 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 92 | | } |
| | | 93 | | // TODO: Decide whether to support DeliveryRequirementsAttribute |
| | | 94 | | //if (typeof(T) == typeof(IBindingDeliveryCapabilities)) |
| | | 95 | | //{ |
| | | 96 | | // return (T)(object)new BindingDeliveryCapabilitiesHelper(); |
| | | 97 | | //} |
| | 338 | 98 | | if (typeof(T) == typeof(ExtendedProtectionPolicy)) |
| | | 99 | | { |
| | 0 | 100 | | return (T)(object)ExtendedProtectionPolicy; |
| | | 101 | | } |
| | 338 | 102 | | else if (typeof(T) == typeof(ITransportCompressionSupport)) |
| | | 103 | | { |
| | 16 | 104 | | return (T)(object)new TransportCompressionSupportHelper(); |
| | | 105 | | } |
| | 322 | 106 | | else if (typeof(T) == typeof(ConnectionPoolSettings)) |
| | | 107 | | { |
| | 0 | 108 | | return (T)(object)_connectionPoolSettings; |
| | | 109 | | } |
| | | 110 | | else |
| | | 111 | | { |
| | 322 | 112 | | return base.GetProperty<T>(context); |
| | | 113 | | } |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | public override IServiceDispatcher BuildServiceDispatcher<TChannel>(BindingContext context, IServiceDispatcher i |
| | | 117 | | { |
| | 105 | 118 | | return innerDispatcher; |
| | | 119 | | } |
| | | 120 | | } |
| | | 121 | | } |