Esempio n. 1
0
        internal void Stop(ushort code, string reason)
        {
            var e     = new CloseEventArgs(code, reason);
            var send  = !code.IsReserved();
            var bytes =
                send ? WebSocketFrame.CreateCloseFrame(e.PayloadData, false).ToByteArray() : null;

            var timeout = send ? WaitTime : TimeSpan.Zero;

            Sessions.Stop(e, bytes, timeout);
        }
        internal void Stop(CloseEventArgs e, bool send, bool wait)
        {
            lock (_sync)
            {
                _state = ServerState.ShuttingDown;
                var bytes = send
                            ? WebSocketFrame.CreateCloseFrame(e.PayloadData, false).ToByteArray()
                            : null;

                var timeout = wait ? _waitTime : TimeSpan.Zero;
                foreach (var host in _hosts.Values)
                {
                    host.Sessions.Stop(e, bytes, timeout);
                }

                _hosts.Clear();
                _state = ServerState.Stop;
            }
        }