IAppSession.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using SuperSocket.Common;
  8. using SuperSocket.SocketBase.Logging;
  9. using SuperSocket.SocketBase.Command;
  10. using SuperSocket.SocketBase.Config;
  11. using SuperSocket.SocketBase.Protocol;
  12. namespace SuperSocket.SocketBase
  13. {
  14. /// <summary>
  15. /// The basic interface for appSession
  16. /// </summary>
  17. public interface IAppSession : ISessionBase
  18. {
  19. /// <summary>
  20. /// Gets the app server.
  21. /// </summary>
  22. IAppServer AppServer { get; }
  23. /// <summary>
  24. /// Gets the socket session of the AppSession.
  25. /// </summary>
  26. ISocketSession SocketSession { get; }
  27. /// <summary>
  28. /// Gets the items.
  29. /// </summary>
  30. IDictionary<object, object> Items { get; }
  31. /// <summary>
  32. /// Gets the config of the server.
  33. /// </summary>
  34. IServerConfig Config { get; }
  35. /// <summary>
  36. /// Gets the local listening endpoint.
  37. /// </summary>
  38. IPEndPoint LocalEndPoint { get; }
  39. /// <summary>
  40. /// Gets or sets the last active time of the session.
  41. /// </summary>
  42. /// <value>
  43. /// The last active time.
  44. /// </value>
  45. DateTime LastActiveTime { get; set; }
  46. /// <summary>
  47. /// Gets the start time of the session.
  48. /// </summary>
  49. DateTime StartTime { get; }
  50. /// <summary>
  51. /// Closes this session.
  52. /// </summary>
  53. void Close();
  54. /// <summary>
  55. /// Closes the session by the specified reason.
  56. /// </summary>
  57. /// <param name="reason">The close reason.</param>
  58. void Close(CloseReason reason);
  59. /// <summary>
  60. /// Gets a value indicating whether this <see cref="IAppSession"/> is connected.
  61. /// </summary>
  62. /// <value>
  63. /// <c>true</c> if connected; otherwise, <c>false</c>.
  64. /// </value>
  65. bool Connected { get; }
  66. /// <summary>
  67. /// Gets or sets the charset which is used for transfering text message.
  68. /// </summary>
  69. /// <value>The charset.</value>
  70. Encoding Charset { get; set; }
  71. /// <summary>
  72. /// Gets or sets the previous command.
  73. /// </summary>
  74. /// <value>
  75. /// The prev command.
  76. /// </value>
  77. string PrevCommand { get; set; }
  78. /// <summary>
  79. /// Gets or sets the current executing command.
  80. /// </summary>
  81. /// <value>
  82. /// The current command.
  83. /// </value>
  84. string CurrentCommand { get; set; }
  85. /// <summary>
  86. /// Gets the logger assosiated with this session.
  87. /// </summary>
  88. ILog Logger { get; }
  89. /// <summary>
  90. /// Processes the request.
  91. /// </summary>
  92. /// <param name="readBuffer">The read buffer.</param>
  93. /// <param name="offset">The offset.</param>
  94. /// <param name="length">The length.</param>
  95. /// <param name="toBeCopied">if set to <c>true</c> [to be copied].</param>
  96. /// <returns>return offset delta of next receiving buffer</returns>
  97. int ProcessRequest(byte[] readBuffer, int offset, int length, bool toBeCopied);
  98. /// <summary>
  99. /// Starts the session.
  100. /// </summary>
  101. void StartSession();
  102. }
  103. /// <summary>
  104. /// The interface for appSession
  105. /// </summary>
  106. /// <typeparam name="TAppSession">The type of the app session.</typeparam>
  107. /// <typeparam name="TRequestInfo">The type of the request info.</typeparam>
  108. public interface IAppSession<TAppSession, TRequestInfo> : IAppSession
  109. where TRequestInfo : IRequestInfo
  110. where TAppSession : IAppSession, IAppSession<TAppSession, TRequestInfo>, new()
  111. {
  112. /// <summary>
  113. /// Initializes the specified session.
  114. /// </summary>
  115. /// <param name="server">The server.</param>
  116. /// <param name="socketSession">The socket session.</param>
  117. void Initialize(IAppServer<TAppSession, TRequestInfo> server, ISocketSession socketSession);
  118. }
  119. }