UdpTransportSettingsElement.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // Author: Atsushi Enomoto <[email protected]>
  3. //
  4. // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining
  7. // a copy of this software and associated documentation files (the
  8. // "Software"), to deal in the Software without restriction, including
  9. // without limitation the rights to use, copy, modify, merge, publish,
  10. // distribute, sublicense, and/or sell copies of the Software, and to
  11. // permit persons to whom the Software is furnished to do so, subject to
  12. // the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be
  15. // included in all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. //
  25. #if NET_4_0
  26. using System;
  27. using System.ComponentModel;
  28. using System.Configuration;
  29. using System.ServiceModel.Configuration;
  30. namespace System.ServiceModel.Discovery.Configuration
  31. {
  32. public sealed class UdpTransportSettingsElement : ConfigurationElement
  33. {
  34. static ConfigurationPropertyCollection properties;
  35. static ConfigurationProperty duplicate_message_history_length, max_buffer_pool_size, max_multicast_retransmit_count, max_pending_message_count, max_received_message_size, max_unicast_retransmit_count, multicast_interface_id,socket_receive_buffer_size, ttl;
  36. static UdpTransportSettingsElement ()
  37. {
  38. duplicate_message_history_length = new ConfigurationProperty ("duplicateMessageHistoryLength", typeof (int), 4112, null, new IntegerValidator (0, int.MaxValue), ConfigurationPropertyOptions.None);
  39. max_buffer_pool_size = new ConfigurationProperty ("maxBufferPoolSize", typeof (long), 0x80000, null, new LongValidator (0, long.MaxValue), ConfigurationPropertyOptions.None);
  40. max_multicast_retransmit_count = new ConfigurationProperty ("maxMulticastRetransmitCount", typeof (int), 2, null, new IntegerValidator (0, int.MaxValue), ConfigurationPropertyOptions.None);
  41. max_pending_message_count = new ConfigurationProperty ("maxPendingMessageCount", typeof (int), 32, null, new IntegerValidator (0, int.MaxValue), ConfigurationPropertyOptions.None);
  42. max_received_message_size = new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), 0xFFE7, null, new LongValidator (0, long.MaxValue), ConfigurationPropertyOptions.None);
  43. max_unicast_retransmit_count = new ConfigurationProperty ("maxUnicastRetransmitCount", typeof (long), 1, null, new IntegerValidator (0, int.MaxValue), ConfigurationPropertyOptions.None);
  44. multicast_interface_id = new ConfigurationProperty ("multicastInterfaceId", typeof (string), null, null, null, ConfigurationPropertyOptions.None);
  45. socket_receive_buffer_size = new ConfigurationProperty ("socketReceiveBufferSize", typeof (int), 0x10000, null, new IntegerValidator (0, int.MaxValue), ConfigurationPropertyOptions.None);
  46. ttl = new ConfigurationProperty ("timeToLive", typeof (int), 1, null, new IntegerValidator (0, int.MaxValue), ConfigurationPropertyOptions.None);
  47. properties = new ConfigurationPropertyCollection ();
  48. ConfigurationProperty [] props = {duplicate_message_history_length, max_buffer_pool_size, max_multicast_retransmit_count, max_pending_message_count, max_received_message_size, max_unicast_retransmit_count, multicast_interface_id, ttl};
  49. foreach (var cp in props)
  50. properties.Add (cp);
  51. }
  52. public UdpTransportSettingsElement ()
  53. {
  54. }
  55. [ConfigurationProperty ("duplicateMessageHistoryLength", DefaultValue = 4112)]
  56. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  57. public int DuplicateMessageHistoryLength {
  58. get { return (int) base [duplicate_message_history_length]; }
  59. set { base [duplicate_message_history_length] = value; }
  60. }
  61. [LongValidator (MinValue = 0, MaxValue = long.MaxValue)]
  62. [ConfigurationProperty ("maxBufferPoolSize", DefaultValue = 0x80000)]
  63. public long MaxBufferPoolSize {
  64. get { return (long) base [max_buffer_pool_size]; }
  65. set { base [max_buffer_pool_size] = value; }
  66. }
  67. [ConfigurationProperty ("maxMulticastRetransmitCount", DefaultValue = 2)]
  68. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  69. public int MaxMulticastRetransmitCount {
  70. get { return (int) base [max_multicast_retransmit_count]; }
  71. set { base [max_multicast_retransmit_count] = value; }
  72. }
  73. [ConfigurationProperty ("maxPendingMessageCount", DefaultValue = 32)]
  74. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  75. public int MaxPendingMessageCount {
  76. get { return (int) base [max_pending_message_count]; }
  77. set { base [max_pending_message_count] = value; }
  78. }
  79. [LongValidator (MinValue = 0, MaxValue = long.MaxValue)]
  80. [ConfigurationProperty ("maxReceivedMessageSize", DefaultValue = 0xFFE7)]
  81. public long MaxReceivedMessageSize {
  82. get { return (long) base [max_received_message_size]; }
  83. set { base [max_received_message_size] = value; }
  84. }
  85. [ConfigurationProperty ("maxUnicastRetransmitCount", DefaultValue = 1)]
  86. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  87. public int MaxUnicastRetransmitCount {
  88. get { return (int) base [max_unicast_retransmit_count]; }
  89. set { base [max_unicast_retransmit_count] = value; }
  90. }
  91. [ConfigurationProperty ("multicastInterfaceId")]
  92. public string MulticastInterfaceId {
  93. get { return (string) base [multicast_interface_id]; }
  94. set { base [multicast_interface_id] = value; }
  95. }
  96. [ConfigurationProperty ("socketReceiveBufferSize", DefaultValue = 0x10000)]
  97. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  98. public int SocketReceiveBufferSize {
  99. get { return (int) base [socket_receive_buffer_size]; }
  100. set { base [socket_receive_buffer_size] = value; }
  101. }
  102. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  103. [ConfigurationProperty ("timeToLive", DefaultValue = 1)]
  104. public int TimeToLive {
  105. get { return (int) base [ttl]; }
  106. set { base [ttl] = value; }
  107. }
  108. protected override ConfigurationPropertyCollection Properties {
  109. get { return properties; }
  110. }
  111. internal void ApplyConfiguration (UdpTransportSettings t)
  112. {
  113. t.DuplicateMessageHistoryLength = DuplicateMessageHistoryLength;
  114. t.MaxBufferPoolSize = MaxBufferPoolSize;
  115. t.MaxMulticastRetransmitCount = MaxMulticastRetransmitCount;
  116. t.MaxPendingMessageCount = MaxPendingMessageCount;
  117. t.MaxReceivedMessageSize = MaxReceivedMessageSize;
  118. t.MaxUnicastRetransmitCount = MaxUnicastRetransmitCount;
  119. t.MulticastInterfaceId = MulticastInterfaceId;
  120. t.SocketReceiveBufferSize = SocketReceiveBufferSize;
  121. t.TimeToLive = TimeToLive;
  122. }
  123. internal void InitializeFrom (UdpTransportSettings t)
  124. {
  125. DuplicateMessageHistoryLength = t.DuplicateMessageHistoryLength;
  126. MaxBufferPoolSize = t.MaxBufferPoolSize;
  127. MaxMulticastRetransmitCount = t.MaxMulticastRetransmitCount;
  128. MaxPendingMessageCount = t.MaxPendingMessageCount;
  129. MaxReceivedMessageSize = t.MaxReceivedMessageSize;
  130. MaxUnicastRetransmitCount = t.MaxUnicastRetransmitCount;
  131. MulticastInterfaceId = t.MulticastInterfaceId;
  132. SocketReceiveBufferSize = t.SocketReceiveBufferSize;
  133. TimeToLive = t.TimeToLive;
  134. }
  135. }
  136. }
  137. #endif