CloseEventArgs.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #region License
  2. /*
  3. * CloseEventArgs.cs
  4. *
  5. * The MIT License
  6. *
  7. * Copyright (c) 2012-2022 sta.blockhead
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. #endregion
  28. using System;
  29. namespace WebSocketSharp
  30. {
  31. /// <summary>
  32. /// Represents the event data for the <see cref="WebSocket.OnClose"/> event.
  33. /// </summary>
  34. /// <remarks>
  35. /// <para>
  36. /// The close event occurs when the WebSocket connection has been closed.
  37. /// </para>
  38. /// <para>
  39. /// If you would like to get the reason for the connection close,
  40. /// you should access the <see cref="Code"/> or <see cref="Reason"/>
  41. /// property.
  42. /// </para>
  43. /// </remarks>
  44. public class CloseEventArgs : EventArgs
  45. {
  46. #region Private Fields
  47. private bool _clean;
  48. private PayloadData _payloadData;
  49. #endregion
  50. #region Internal Constructors
  51. internal CloseEventArgs (PayloadData payloadData, bool clean)
  52. {
  53. _payloadData = payloadData;
  54. _clean = clean;
  55. }
  56. #endregion
  57. #region Public Properties
  58. /// <summary>
  59. /// Gets the status code for the connection close.
  60. /// </summary>
  61. /// <value>
  62. /// <para>
  63. /// A <see cref="ushort"/> that represents the status code for
  64. /// the connection close.
  65. /// </para>
  66. /// <para>
  67. /// 1005 (no status) if not present.
  68. /// </para>
  69. /// </value>
  70. public ushort Code {
  71. get {
  72. return _payloadData.Code;
  73. }
  74. }
  75. /// <summary>
  76. /// Gets the reason for the connection close.
  77. /// </summary>
  78. /// <value>
  79. /// <para>
  80. /// A <see cref="string"/> that represents the reason for
  81. /// the connection close.
  82. /// </para>
  83. /// <para>
  84. /// An empty string if not present.
  85. /// </para>
  86. /// </value>
  87. public string Reason {
  88. get {
  89. return _payloadData.Reason;
  90. }
  91. }
  92. /// <summary>
  93. /// Gets a value indicating whether the connection has been closed cleanly.
  94. /// </summary>
  95. /// <value>
  96. /// <c>true</c> if the connection has been closed cleanly; otherwise,
  97. /// <c>false</c>.
  98. /// </value>
  99. public bool WasClean {
  100. get {
  101. return _clean;
  102. }
  103. }
  104. #endregion
  105. }
  106. }