UdpTransportSettingsElement.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. ttl = new ConfigurationProperty ("timeToLive", typeof (int), 1, null, new IntegerValidator (0, int.MaxValue), ConfigurationPropertyOptions.None);
  46. properties = new ConfigurationPropertyCollection ();
  47. 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};
  48. foreach (var cp in props)
  49. properties.Add (cp);
  50. }
  51. public UdpTransportSettingsElement ()
  52. {
  53. }
  54. [ConfigurationProperty ("duplicateMessageHistoryLength", DefaultValue = 4112)]
  55. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  56. public int DuplicateMessageHistoryLength {
  57. get { return (int) base [duplicate_message_history_length]; }
  58. set { base [duplicate_message_history_length] = value; }
  59. }
  60. [LongValidator (MinValue = 0, MaxValue = long.MaxValue)]
  61. [ConfigurationProperty ("maxBufferPoolSize", DefaultValue = 0x80000)]
  62. public long MaxBufferPoolSize {
  63. get { return (long) base [max_buffer_pool_size]; }
  64. set { base [max_buffer_pool_size] = value; }
  65. }
  66. [ConfigurationProperty ("maxMulticastRetransmitCount", DefaultValue = 2)]
  67. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  68. public int MaxMulticastRetransmitCount {
  69. get { return (int) base [max_multicast_retransmit_count]; }
  70. set { base [max_multicast_retransmit_count] = value; }
  71. }
  72. [ConfigurationProperty ("maxPendingMessageCount", DefaultValue = 32)]
  73. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  74. public int MaxPendingMessageCount {
  75. get { return (int) base [max_pending_message_count]; }
  76. set { base [max_pending_message_count] = value; }
  77. }
  78. [LongValidator (MinValue = 0, MaxValue = long.MaxValue)]
  79. [ConfigurationProperty ("maxReceivedMessageSize", DefaultValue = 0xFFE7)]
  80. public long MaxReceivedMessageSize {
  81. get { return (long) base [max_received_message_size]; }
  82. set { base [max_received_message_size] = value; }
  83. }
  84. [ConfigurationProperty ("maxUnicastRetransmitCount", DefaultValue = 1)]
  85. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  86. public int MaxUnicastRetransmitCount {
  87. get { return (int) base [max_unicast_retransmit_count]; }
  88. set { base [max_unicast_retransmit_count] = value; }
  89. }
  90. [ConfigurationProperty ("multicastInterfaceId")]
  91. public string MulticastInterfaceId {
  92. get { return (string) base [multicast_interface_id]; }
  93. set { base [multicast_interface_id] = value; }
  94. }
  95. [ConfigurationProperty ("socketReceiveBufferSize", DefaultValue = 0x10000)]
  96. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  97. public int SocketReceiveBufferSize {
  98. get { return (int) base [socket_receive_buffer_size]; }
  99. set { base [socket_receive_buffer_size] = value; }
  100. }
  101. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  102. [ConfigurationProperty ("timeToLive", DefaultValue = 1)]
  103. public int TimeToLive {
  104. get { return (int) base [ttl]; }
  105. set { base [ttl] = value; }
  106. }
  107. protected override ConfigurationPropertyCollection Properties {
  108. get { return properties; }
  109. }
  110. internal void ApplyConfiguration (UdpTransportSettings t)
  111. {
  112. t.DuplicateMessageHistoryLength = DuplicateMessageHistoryLength;
  113. t.MaxBufferPoolSize = MaxBufferPoolSize;
  114. t.MaxMulticastRetransmitCount = MaxMulticastRetransmitCount;
  115. t.MaxPendingMessageCount = MaxPendingMessageCount;
  116. t.MaxReceivedMessageSize = MaxReceivedMessageSize;
  117. t.MaxUnicastRetransmitCount = MaxUnicastRetransmitCount;
  118. t.MulticastInterfaceId = MulticastInterfaceId;
  119. t.SocketReceiveBufferSize = SocketReceiveBufferSize;
  120. t.TimeToLive = TimeToLive;
  121. }
  122. internal void InitializeFrom (UdpTransportSettings t)
  123. {
  124. DuplicateMessageHistoryLength = t.DuplicateMessageHistoryLength;
  125. MaxBufferPoolSize = t.MaxBufferPoolSize;
  126. MaxMulticastRetransmitCount = t.MaxMulticastRetransmitCount;
  127. MaxPendingMessageCount = t.MaxPendingMessageCount;
  128. MaxReceivedMessageSize = t.MaxReceivedMessageSize;
  129. MaxUnicastRetransmitCount = t.MaxUnicastRetransmitCount;
  130. MulticastInterfaceId = t.MulticastInterfaceId;
  131. SocketReceiveBufferSize = t.SocketReceiveBufferSize;
  132. TimeToLive = t.TimeToLive;
  133. }
  134. }
  135. }
  136. #endif