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; } }
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; } }
private WebSocketHandle(WinHttpWebSocket webSocket) { _webSocket = webSocket; }