12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SuperSocket.SocketBase;
- using SuperSocket.SocketBase.Command;
- using SuperWebSocket.Protocol;
- namespace SuperWebSocket.Command
- {
-
-
-
-
- class Close<TWebSocketSession> : FragmentCommand<TWebSocketSession>
- where TWebSocketSession : WebSocketSession<TWebSocketSession>, new()
- {
-
-
-
- public override string Name
- {
- get
- {
- return OpCode.CloseTag;
- }
- }
-
-
-
-
-
- public override void ExecuteCommand(TWebSocketSession session, IWebSocketFragment requestInfo)
- {
- var frame = requestInfo as WebSocketDataFrame;
- if (!CheckControlFrame(frame))
- {
- session.Close();
- return;
- }
-
- if (session.InClosing)
- {
-
- session.Close(CloseReason.ClientClosing);
- return;
- }
- var data = GetWebSocketData(frame);
- var closeStatusCode = session.ProtocolProcessor.CloseStatusClode.NormalClosure;
-
- if (data != null && data.Length > 0)
- {
- if (data.Length == 1)
- {
- session.Close(CloseReason.ProtocolError);
- return;
- }
- else
- {
- var code = data[0] * 256 + data[1];
- if (!session.ProtocolProcessor.IsValidCloseCode(code))
- {
- session.Close(CloseReason.ProtocolError);
- return;
- }
- closeStatusCode = code;
-
-
-
-
- }
- }
-
- session.SendCloseHandshakeResponse(closeStatusCode);
-
-
-
- session.Close(CloseReason.ClientClosing);
- }
- }
- }
|