Exemplo n.º 1
0
 public override void Abort()
 {
     if ((InternalState)_state == InternalState.Disposed)
     {
         return;
     }
     if (WebSocketHandle.IsValid(_innerWebSocket))
     {
         _innerWebSocket.Abort();
     }
     Dispose();
 }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
0
        public ClientWebSocket()
        {
            if (NetEventSource.Log.IsEnabled())
            {
                NetEventSource.Enter(NetEventSource.ComponentType.WebSocket, this, ".ctor", null);
            }

            WebSocketHandle.CheckPlatformSupport();

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

            if (NetEventSource.Log.IsEnabled())
            {
                NetEventSource.Exit(NetEventSource.ComponentType.WebSocket, this, ".ctor", null);
            }
        }
Exemplo n.º 5
0
        public ClientWebSocket()
        {
            if (Logging.On)
            {
                Logging.Enter(Logging.WebSockets, this, ".ctor", null);
            }

            WebSocketHandle.CheckPlatformSupport();

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

            if (Logging.On)
            {
                Logging.Exit(Logging.WebSockets, this, ".ctor", null);
            }
        }
Exemplo n.º 6
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.Log.IsEnabled())
                {
                    NetEventSource.Exception(NetEventSource.ComponentType.WebSocket, this, "ConnectAsync", ex);
                }
                throw;
            }
        }
Exemplo n.º 7
0
 public ClientWebSocket()
 {
     _state  = (int)InternalState.Created;
     Options = WebSocketHandle.CreateDefaultOptions();
 }
 public static bool IsValid(WebSocketHandle handle)
 {
     return(handle._webSocket != null);
 }
Exemplo n.º 9
0
 public static bool IsValid(WebSocketHandle handle) => handle != null;
Exemplo n.º 10
0
 public static bool IsValid(WebSocketHandle handle) => handle != null;
        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;
            }
        }
Exemplo n.º 12
0
 public static bool IsValid(WebSocketHandle handle)
 {
     return handle._webSocket != null;
 }