using System; using System.Collections.Generic; using System.Linq; using System.Text; using SuperSocket.Common; using SuperSocket.SocketBase; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; namespace SuperWebSocket.Protocol { /// /// WebSocketReceiveFilter basis /// public abstract class WebSocketReceiveFilterBase : ReceiveFilterBase { /// /// The length of Sec3Key /// protected const int SecKey3Len = 8; private readonly IWebSocketSession m_Session; internal IWebSocketSession Session { get { return m_Session; } } static WebSocketReceiveFilterBase() { HandshakeRequestInfo = new HandshakeRequest(); } /// /// Initializes a new instance of the class. /// /// The session. protected WebSocketReceiveFilterBase(IWebSocketSession session) { m_Session = session; } /// /// Initializes a new instance of the class. /// /// The previous receive filter. protected WebSocketReceiveFilterBase(WebSocketReceiveFilterBase previousReceiveFilter) : base(previousReceiveFilter) { m_Session = previousReceiveFilter.Session; } /// /// Handshakes the specified protocol processor. /// /// The protocol processor. /// The session. /// protected bool Handshake(IProtocolProcessor protocolProcessor, IWebSocketSession session) { IReceiveFilter dataFrameReader; if (!protocolProcessor.Handshake(session, this, out dataFrameReader)) { session.Close(CloseReason.ServerClosing); return false; } //Processor handshake sucessfully, but output datareader is null, so the multiple protocol switch handled the handshake //In this case, the handshake is not completed if (dataFrameReader == null) { NextReceiveFilter = this; return false; } NextReceiveFilter = dataFrameReader; return true; } /// /// Gets the handshake request info. /// protected static IWebSocketFragment HandshakeRequestInfo { get; private set; } } }