using System; using System.Collections.Generic; using System.Linq; using System.Text; using SuperSocket.SocketBase.Protocol; using SuperSocket.SocketBase; namespace SuperWebSocket.Protocol { /// /// Protocol processor interface /// public interface IProtocolProcessor { /// /// Gets a value indicating whether this instance can send binary data. /// /// /// true if this instance can send binary data; otherwise, false. /// bool CanSendBinaryData { get; } /// /// Gets the close status clode. /// ICloseStatusCode CloseStatusClode { get; } /// /// Gets or sets the next processor. /// /// /// The next processor. /// IProtocolProcessor NextProcessor { get; set; } /// /// Handshakes the specified session. /// /// The session. /// The previous filter. /// The data frame reader. /// bool Handshake(IWebSocketSession session, WebSocketReceiveFilterBase previousFilter, out IReceiveFilter dataFrameReader); /// /// Gets the encoded package. /// /// The op code. /// The data. /// The offset. /// The length. /// IList> GetEncodedPackage(int opCode, byte[] data, int offset, int length); /// /// Gets the encoded package. /// /// The op code. /// The message. /// IList> GetEncodedPackage(int opCode, string message); /// /// Sends the message. /// /// The session. /// The message. void SendMessage(IWebSocketSession session, string message); /// /// Try to send the message. /// /// The session. /// The message. /// 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 bool TrySendMessage(IWebSocketSession session, string message); /// /// Sends the data. /// /// The session. /// The data. /// The offset. /// The length. void SendData(IWebSocketSession session, byte[] data, int offset, int length); /// /// Try to send the data. /// /// The session. /// The data. /// The offset. /// The length. /// 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 bool TrySendData(IWebSocketSession session, byte[] data, int offset, int length); /// /// Sends the close handshake. /// /// The session. /// The status code. /// The close reason. void SendCloseHandshake(IWebSocketSession session, int statusCode, string closeReason); /// /// Sends the pong. /// /// The session. /// The pong. void SendPong(IWebSocketSession session, byte[] pong); /// /// Sends the ping. /// /// The session. /// The ping. void SendPing(IWebSocketSession session, byte[] ping); /// /// Gets the version of current protocol. /// int Version { get; } /// /// Determines whether [is valid close code] [the specified code]. /// /// The code. /// /// true if [is valid close code] [the specified code]; otherwise, false. /// bool IsValidCloseCode(int code); } }