IAppSession.cs 4.1 KB

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