private void close(PayloadData payload, bool send, bool wait) { lock (_forConn) { if (_readyState == WebSocketState.Closing || _readyState == WebSocketState.Closed) { return; } _readyState = WebSocketState.Closing; } var e = new CloseEventArgs(payload); e.WasClean = closeHandshake( send ? WebSocketFrame.CreateCloseFrame(Mask.Unmask, payload).ToByteArray() : null, wait ? 1000 : 0, closeServerResources); _readyState = WebSocketState.Closed; try { OnClose.Emit(this, e); } catch (Exception ex) { error("An exception has occurred while OnClose.", ex); } }
private async Task CloseAsync(PayloadData payload, bool send, bool wait) { lock (_forConn) { if (_readyState == WebSocketState.CloseSent || _readyState == WebSocketState.Closed) { return; } _readyState = WebSocketState.CloseSent; } var e = new CloseEventArgs(payload) { WasClean = await CloseHandshakeAsync( send?WebSocketFrame.CreateCloseFrame(Mask.Unmask, payload).ToByteArray() : null, wait? 1000 : 0).ConfigureAwait(false) }; _readyState = WebSocketState.Closed; try { OnClose.Emit(this, e); } catch (Exception ex) { error("An exception has occurred while OnClose.", ex); } }