Beispiel #1
0
        private Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)
        {
            var winHttpWebSocket = new WinHttpWebSocket();

            _innerWebSocket = winHttpWebSocket;

            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);
                }

                return(winHttpWebSocket.ConnectAsync(uri, cancellationToken, _options));
            }
            catch (Win32Exception ex)
            {
                WebSocketException wex = new WebSocketException(SR.net_webstatus_ConnectFailure, ex);
                if (Logging.On)
                {
                    Logging.Exception(Logging.WebSockets, this, "ConnectAsync", wex);
                }
                throw wex;
            }
            catch (Exception ex)
            {
                if (Logging.On)
                {
                    Logging.Exception(Logging.WebSockets, this, "ConnectAsync", ex);
                }
                throw;
            }
        }
Beispiel #2
0
 public async Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)
 {
     try
     {
         await _webSocket.ConnectAsync(uri, cancellationToken, options).ConfigureAwait(false);
     }
     catch (Win32Exception ex)
     {
         WebSocketException wex = new WebSocketException(SR.net_webstatus_ConnectFailure, ex);
         if (NetEventSource.Log.IsEnabled())
         {
             NetEventSource.Exception(NetEventSource.ComponentType.WebSocket, this, "ConnectAsync", wex);
         }
         throw wex;
     }
 }
 public async Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)
 {
     try
     {
         await _webSocket.ConnectAsync(uri, cancellationToken, options).ConfigureAwait(false);
     }
     catch (Win32Exception ex)
     {
         WebSocketException wex = new WebSocketException(SR.net_webstatus_ConnectFailure, ex);
         if (Logging.On)
         {
             Logging.Exception(Logging.WebSockets, this, "ConnectAsync", wex);
         }
         throw wex;
     }
 }
Beispiel #4
0
        private Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)
        {
            _innerWebSocket = new WinHttpWebSocket();

            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);
                }

                return _innerWebSocket.ConnectAsync(uri, cancellationToken, _options);
            }
            catch (Win32Exception ex)
            {
                WebSocketException wex = new WebSocketException(SR.net_webstatus_ConnectFailure, ex);
                if (Logging.On)
                {
                    Logging.Exception(Logging.WebSockets, this, "ConnectAsync", wex);
                }
                throw wex;
            }
            catch (Exception ex)
            {
                if (Logging.On)
                {
                    Logging.Exception(Logging.WebSockets, this, "ConnectAsync", ex);
                }
                throw;
            }
        }