Ejemplo n.º 1
0
        // <RELAY_CUSTOM Comment="Check if all the .NET CoreApp 2.1+ types we use via reflection are available">
        internal static bool IsSupported()
        {
            if (!isSupported.HasValue)
            {
                isSupported = SocketsHttpHandler.IsSupported() &&
                              SslClientAuthenticationOptions.IsSupported() &&
                              WebSocketHandle.IsSupported();
            }

            return(isSupported.Value);
        }
Ejemplo n.º 2
0
 public override void Abort()
 {
     if ((InternalState)_state == InternalState.Disposed)
     {
         return;
     }
     if (WebSocketHandle.IsValid(_innerWebSocket))
     {
         _innerWebSocket.Abort();
     }
     Dispose();
 }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        public ClientWebSocket()
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this);
            }
            WebSocketHandle.CheckPlatformSupport();

            _state   = (int)InternalState.Created;
            _options = new ClientWebSocketOptions()
            {
                Proxy = DefaultWebProxy.Instance
            };

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(this);
            }
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
0
 public static bool IsValid(WebSocketHandle handle) => handle != null;