ISocketSession.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Net;
  7. using System.Security.Authentication;
  8. using System.Net.Sockets;
  9. using SuperSocket.SocketBase.Command;
  10. namespace SuperSocket.SocketBase
  11. {
  12. /// <summary>
  13. /// CloseReason enum
  14. /// </summary>
  15. public enum CloseReason : int
  16. {
  17. /// <summary>
  18. /// The socket is closed for unknown reason
  19. /// </summary>
  20. Unknown = 0,
  21. /// <summary>
  22. /// Close for server shutdown
  23. /// </summary>
  24. ServerShutdown = 1,
  25. /// <summary>
  26. /// The client close the socket
  27. /// </summary>
  28. ClientClosing = 2,
  29. /// <summary>
  30. /// The server side close the socket
  31. /// </summary>
  32. ServerClosing = 3,
  33. /// <summary>
  34. /// Application error
  35. /// </summary>
  36. ApplicationError = 4,
  37. /// <summary>
  38. /// The socket is closed for a socket error
  39. /// </summary>
  40. SocketError = 5,
  41. /// <summary>
  42. /// The socket is closed by server for timeout
  43. /// </summary>
  44. TimeOut = 6,
  45. /// <summary>
  46. /// Protocol error
  47. /// </summary>
  48. ProtocolError = 7,
  49. /// <summary>
  50. /// SuperSocket internal error
  51. /// </summary>
  52. InternalError = 8,
  53. }
  54. /// <summary>
  55. /// The interface for socket session
  56. /// </summary>
  57. public interface ISocketSession : ISessionBase
  58. {
  59. /// <summary>
  60. /// Initializes the specified app session.
  61. /// </summary>
  62. /// <param name="appSession">The app session.</param>
  63. void Initialize(IAppSession appSession);
  64. /// <summary>
  65. /// Starts this instance.
  66. /// </summary>
  67. void Start();
  68. /// <summary>
  69. /// Closes the socket session for the specified reason.
  70. /// </summary>
  71. /// <param name="reason">The reason.</param>
  72. void Close(CloseReason reason);
  73. /// <summary>
  74. /// Tries to send array segment.
  75. /// </summary>
  76. /// <param name="segments">The segments.</param>
  77. bool TrySend(IList<ArraySegment<byte>> segments);
  78. /// <summary>
  79. /// Tries to send array segment.
  80. /// </summary>
  81. /// <param name="segment">The segment.</param>
  82. bool TrySend(ArraySegment<byte> segment);
  83. /// <summary>
  84. /// Applies the secure protocol.
  85. /// </summary>
  86. void ApplySecureProtocol();
  87. /// <summary>
  88. /// Gets the client socket.
  89. /// </summary>
  90. Socket Client { get; }
  91. /// <summary>
  92. /// Gets the local listening endpoint.
  93. /// </summary>
  94. IPEndPoint LocalEndPoint { get; }
  95. /// <summary>
  96. /// Gets or sets the secure protocol.
  97. /// </summary>
  98. /// <value>
  99. /// The secure protocol.
  100. /// </value>
  101. SslProtocols SecureProtocol { get; set; }
  102. /// <summary>
  103. /// Occurs when [closed].
  104. /// </summary>
  105. Action<ISocketSession, CloseReason> Closed { get; set; }
  106. /// <summary>
  107. /// Gets the app session assosiated with this socket session.
  108. /// </summary>
  109. IAppSession AppSession { get; }
  110. /// <summary>
  111. /// Gets the original receive buffer offset.
  112. /// </summary>
  113. /// <value>
  114. /// The original receive buffer offset.
  115. /// </value>
  116. int OrigReceiveOffset { get; }
  117. }
  118. }