public override void Abort() { if ((InternalState)_state == InternalState.Disposed) { return; } if (WebSocketHandle.IsValid(_innerWebSocket)) { _innerWebSocket.Abort(); } Dispose(); }
public override void Dispose() { var priorState = (InternalState)Interlocked.Exchange(ref _state, (int)InternalState.Disposed); if (priorState == InternalState.Disposed) { // No cleanup required. return; } if (WebSocketHandle.IsValid(_innerWebSocket)) { _innerWebSocket.Dispose(); } }
public ClientWebSocket() { if (NetEventSource.IsEnabled) { NetEventSource.Enter(this); } WebSocketHandle.CheckPlatformSupport(); _state = (int)InternalState.Created; _options = new ClientWebSocketOptions(); if (NetEventSource.IsEnabled) { NetEventSource.Exit(this); } }
private async Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken) { _innerWebSocket = WebSocketHandle.Create(); try { // Change internal state to 'connected' to enable the other methods if ((InternalState)Interlocked.CompareExchange(ref _state, (int)InternalState.Connected, (int)InternalState.Connecting) != InternalState.Connecting) { // Aborted/Disposed during connect. throw new ObjectDisposedException(GetType().FullName); } await _innerWebSocket.ConnectAsyncCore(uri, cancellationToken, this, _options).ConfigureAwait(false); } catch (Exception ex) { if (NetEventSource.IsEnabled) { NetEventSource.Error(this, ex); } throw; } }
public static bool IsValid(WebSocketHandle handle) => handle != null;