IProtocolProcessor.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SuperSocket.SocketBase.Protocol;
  6. using SuperSocket.SocketBase;
  7. namespace SuperWebSocket.Protocol
  8. {
  9. /// <summary>
  10. /// Protocol processor interface
  11. /// </summary>
  12. public interface IProtocolProcessor
  13. {
  14. /// <summary>
  15. /// Gets a value indicating whether this instance can send binary data.
  16. /// </summary>
  17. /// <value>
  18. /// <c>true</c> if this instance can send binary data; otherwise, <c>false</c>.
  19. /// </value>
  20. bool CanSendBinaryData { get; }
  21. /// <summary>
  22. /// Gets the close status clode.
  23. /// </summary>
  24. ICloseStatusCode CloseStatusClode { get; }
  25. /// <summary>
  26. /// Gets or sets the next processor.
  27. /// </summary>
  28. /// <value>
  29. /// The next processor.
  30. /// </value>
  31. IProtocolProcessor NextProcessor { get; set; }
  32. /// <summary>
  33. /// Handshakes the specified session.
  34. /// </summary>
  35. /// <param name="session">The session.</param>
  36. /// <param name="previousFilter">The previous filter.</param>
  37. /// <param name="dataFrameReader">The data frame reader.</param>
  38. /// <returns></returns>
  39. bool Handshake(IWebSocketSession session, WebSocketReceiveFilterBase previousFilter, out IReceiveFilter<IWebSocketFragment> dataFrameReader);
  40. /// <summary>
  41. /// Gets the encoded package.
  42. /// </summary>
  43. /// <param name="opCode">The op code.</param>
  44. /// <param name="data">The data.</param>
  45. /// <param name="offset">The offset.</param>
  46. /// <param name="length">The length.</param>
  47. /// <returns></returns>
  48. IList<ArraySegment<byte>> GetEncodedPackage(int opCode, byte[] data, int offset, int length);
  49. /// <summary>
  50. /// Gets the encoded package.
  51. /// </summary>
  52. /// <param name="opCode">The op code.</param>
  53. /// <param name="message">The message.</param>
  54. /// <returns></returns>
  55. IList<ArraySegment<byte>> GetEncodedPackage(int opCode, string message);
  56. /// <summary>
  57. /// Sends the message.
  58. /// </summary>
  59. /// <param name="session">The session.</param>
  60. /// <param name="message">The message.</param>
  61. void SendMessage(IWebSocketSession session, string message);
  62. /// <summary>
  63. /// Try to send the message.
  64. /// </summary>
  65. /// <param name="session">The session.</param>
  66. /// <param name="message">The message.</param>
  67. /// <returns>if the messaged has been enqueued into the sending queue, return true; else if the message failed to be enqueued becuase the sending is full, then return false</returns>
  68. bool TrySendMessage(IWebSocketSession session, string message);
  69. /// <summary>
  70. /// Sends the data.
  71. /// </summary>
  72. /// <param name="session">The session.</param>
  73. /// <param name="data">The data.</param>
  74. /// <param name="offset">The offset.</param>
  75. /// <param name="length">The length.</param>
  76. void SendData(IWebSocketSession session, byte[] data, int offset, int length);
  77. /// <summary>
  78. /// Try to send the data.
  79. /// </summary>
  80. /// <param name="session">The session.</param>
  81. /// <param name="data">The data.</param>
  82. /// <param name="offset">The offset.</param>
  83. /// <param name="length">The length.</param>
  84. /// <returns>if the data has been enqueued into the sending queue, return true; else if the data failed to be enqueued becuase the sending is full, then return false</returns>
  85. bool TrySendData(IWebSocketSession session, byte[] data, int offset, int length);
  86. /// <summary>
  87. /// Sends the close handshake.
  88. /// </summary>
  89. /// <param name="session">The session.</param>
  90. /// <param name="statusCode">The status code.</param>
  91. /// <param name="closeReason">The close reason.</param>
  92. void SendCloseHandshake(IWebSocketSession session, int statusCode, string closeReason);
  93. /// <summary>
  94. /// Sends the pong.
  95. /// </summary>
  96. /// <param name="session">The session.</param>
  97. /// <param name="pong">The pong.</param>
  98. void SendPong(IWebSocketSession session, byte[] pong);
  99. /// <summary>
  100. /// Sends the ping.
  101. /// </summary>
  102. /// <param name="session">The session.</param>
  103. /// <param name="ping">The ping.</param>
  104. void SendPing(IWebSocketSession session, byte[] ping);
  105. /// <summary>
  106. /// Gets the version of current protocol.
  107. /// </summary>
  108. int Version { get; }
  109. /// <summary>
  110. /// Determines whether [is valid close code] [the specified code].
  111. /// </summary>
  112. /// <param name="code">The code.</param>
  113. /// <returns>
  114. /// <c>true</c> if [is valid close code] [the specified code]; otherwise, <c>false</c>.
  115. /// </returns>
  116. bool IsValidCloseCode(int code);
  117. }
  118. }