예제 #1
0
 public override void Abort()
 {
     if ((InternalState)_state == InternalState.Disposed)
     {
         return;
     }
     if (WebSocketHandle.IsValid(_innerWebSocket))
     {
         _innerWebSocket.Abort();
     }
     Dispose();
 }
예제 #2
0
        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();
            }
        }
예제 #3
0
        public ClientWebSocket()
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this);
            }
            WebSocketHandle.CheckPlatformSupport();

            _state   = (int)InternalState.Created;
            _options = new ClientWebSocketOptions();

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(this);
            }
        }
예제 #4
0
        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, _options).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                if (NetEventSource.IsEnabled)
                {
                    NetEventSource.Error(this, ex);
                }
                throw;
            }
        }
예제 #5
0
 public static bool IsValid(WebSocketHandle handle) => handle != null;