Beispiel #1
0
 private void closeAsync(CloseEventArgs e, bool send, bool receive, bool received)
 {
     Action<CloseEventArgs, bool, bool, bool> closer = close;
     closer.BeginInvoke(e, send, receive, received, ar => closer.EndInvoke(ar), null);
 }
Beispiel #2
0
        // As server
        internal void Close(CloseEventArgs e, byte[] frameAsBytes, bool receive)
        {
            lock (_forState)
            {
                if (_readyState == WebSocketState.Closing)
                {
#if COMPAT
                    Log.Info("The closing is already in progress.");
#endif
                    return;
                }

                if (_readyState == WebSocketState.Closed)
                {
#if COMPAT
                    Log.Info("The connection has been closed.");
#endif
                    return;
                }

                _readyState = WebSocketState.Closing;
            }

            e.WasClean = CloseHandshake(frameAsBytes, receive, false);
            ReleaseServerResources();
            ReleaseCommonResources();

            _readyState = WebSocketState.Closed;

            try
            {
                OnClose?.Invoke(this, e);
            }
            catch (Exception ex)
            {
#if COMPAT
                    Log.Error(ex.ToString());
#else
                ex.Log();
#endif
            }
        }
Beispiel #3
0
        private void close(CloseEventArgs e, bool send, bool receive, bool received)
        {
            lock (_forState)
            {
                if (_readyState == WebSocketState.Closing)
                {
#if COMPAT
                    Log.Info("The closing is already in progress.");
#else
                    "The closing is already in progress.".Info();
#endif
                    return;
                }

                if (_readyState == WebSocketState.Closed)
                {
#if COMPAT
                    Log.Info("The connection has been closed.");
#else
                    "The connection has been closed.".Info();
#endif
                    return;
                }

                send = send && _readyState == WebSocketState.Open;
                receive = receive && send;

                _readyState = WebSocketState.Closing;
            }

#if COMPAT
            Log.Info("Begin closing the connection.");
#else
            "Begin closing the connection.".Info();
#endif

            var bytes = send ? WebSocketFrame.CreateCloseFrame(e.PayloadData, _client).ToArray() : null;
            e.WasClean = CloseHandshake(bytes, receive, received);
            ReleaseResources();

#if COMPAT
            Log.Info("End closing the connection.");
#else
            "End closing the connection.".Info();
#endif

            _readyState = WebSocketState.Closed;

            try
            {
                OnClose?.Invoke(this, e);
            }
            catch (Exception ex)
            {
#if COMPAT
                    Log.Error(ex.ToString());
#else
                ex.Log();
#endif
                Error("An exception has occurred during the OnClose event.", ex);
            }
        }