private ValueTask ShutdownAsync( QUIC_CONNECTION_SHUTDOWN_FLAG Flags, long ErrorCode) { uint status = MsQuicApi.Api.ConnectionShutdownDelegate( _ptr, (uint)Flags, ErrorCode); QuicExceptionHelpers.ThrowIfFailed(status, "Failed to shutdown connection."); return(_shutdownTcs.GetTypelessValueTask()); }
internal override ValueTask ConnectAsync(CancellationToken cancellationToken = default) { ThrowIfDisposed(); MsQuicStatusException.ThrowIfFailed( MsQuicApi.Api.ConnectionStartDelegate( _ptr, (ushort)_remoteEndPoint.AddressFamily, _remoteEndPoint.Address.ToString(), (ushort)_remoteEndPoint.Port)); return(_connectTcs.GetTypelessValueTask()); }
private async ValueTask <CancellationTokenRegistration> HandleWriteStartState(CancellationToken cancellationToken) { if (!_canWrite) { throw new InvalidOperationException("Writing is not allowed on stream."); } lock (_sync) { if (_sendState == SendState.Aborted) { throw new OperationCanceledException("Sending has already been aborted on the stream"); } } CancellationTokenRegistration registration = cancellationToken.Register(() => { bool shouldComplete = false; lock (_sync) { if (_sendState == SendState.None) { _sendState = SendState.Aborted; shouldComplete = true; } } if (shouldComplete) { _sendResettableCompletionSource.CompleteException(new OperationCanceledException("Write was canceled", cancellationToken)); } }); // Make sure start has completed if (!_started) { await _sendResettableCompletionSource.GetTypelessValueTask().ConfigureAwait(false); _started = true; } return(registration); }
private ValueTask ShutdownAsync( QUIC_CONNECTION_SHUTDOWN_FLAG Flags, long ErrorCode) { if (NetEventSource.IsEnabled) { NetEventSource.Enter(this); } uint status = MsQuicApi.Api.ConnectionShutdownDelegate( _ptr, (uint)Flags, ErrorCode); QuicExceptionHelpers.ThrowIfFailed(status, "Failed to shutdown connection."); if (NetEventSource.IsEnabled) { NetEventSource.Exit(this); } return(_shutdownTcs.GetTypelessValueTask()); }