@@ -104,7 +104,7 @@ internal unsafe QuicStream(MsQuicContextSafeHandle connectionHandle, QuicStreamT
104104 try
105105 {
106106 QUIC_HANDLE * handle ;
107- ThrowIfFailure ( MsQuicApi . Api . ApiTable ->StreamOpen (
107+ ThrowHelper . ThrowIfMsQuicError ( MsQuicApi . Api . ApiTable ->StreamOpen (
108108 connectionHandle . QuicHandle ,
109109 type == QuicStreamType . Unidirectional ? QUIC_STREAM_OPEN_FLAGS . UNIDIRECTIONAL : QUIC_STREAM_OPEN_FLAGS . NONE ,
110110 & NativeCallback ,
@@ -181,7 +181,7 @@ internal ValueTask StartAsync(CancellationToken cancellationToken = default)
181181 if ( StatusFailed ( status ) )
182182 {
183183 // TODO: aborted and the exception type
184- _startedTcs . TrySetException ( new MsQuicException ( status ) ) ;
184+ _startedTcs . TrySetException ( ThrowHelper . GetExceptionForMsQuicStatus ( status ) ) ;
185185 }
186186 }
187187 }
@@ -250,7 +250,7 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
250250 {
251251 unsafe
252252 {
253- ThrowIfFailure ( MsQuicApi . Api . ApiTable ->StreamReceiveSetEnabled (
253+ ThrowHelper . ThrowIfMsQuicError ( MsQuicApi . Api . ApiTable ->StreamReceiveSetEnabled (
254254 _handle . QuicHandle ,
255255 1 ) ) ;
256256 }
@@ -311,7 +311,7 @@ public ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool completeWrites, Ca
311311 _sendBuffers . Initialize ( buffer ) ;
312312 unsafe
313313 {
314- ThrowIfFailure ( MsQuicApi . Api . ApiTable ->StreamSend (
314+ ThrowHelper . ThrowIfMsQuicError ( MsQuicApi . Api . ApiTable ->StreamSend (
315315 _handle . QuicHandle ,
316316 _sendBuffers . Buffers ,
317317 ( uint ) _sendBuffers . Count ,
@@ -341,14 +341,14 @@ public void Abort(QuicAbortDirection abortDirection, long errorCode)
341341 if ( abortDirection . HasFlag ( QuicAbortDirection . Read ) )
342342 {
343343 flags |= QUIC_STREAM_SHUTDOWN_FLAGS . ABORT_RECEIVE ;
344- if ( _receiveTcs . TrySetException ( new QuicOperationAbortedException ( "Read was aborted" ) , final : true ) )
344+ if ( _receiveTcs . TrySetException ( ThrowHelper . GetOperationAbortedException ( "Read was aborted" ) , final : true ) )
345345 {
346346 flags |= QUIC_STREAM_SHUTDOWN_FLAGS . ABORT_RECEIVE ;
347347 }
348348 }
349349 if ( abortDirection . HasFlag ( QuicAbortDirection . Write ) )
350350 {
351- if ( _sendTcs . TrySetException ( new QuicOperationAbortedException ( "Write was aborted" ) , final : true ) )
351+ if ( _sendTcs . TrySetException ( ThrowHelper . GetOperationAbortedException ( "Write was aborted" ) , final : true ) )
352352 {
353353 flags |= QUIC_STREAM_SHUTDOWN_FLAGS . ABORT_SEND ;
354354 }
@@ -361,7 +361,7 @@ public void Abort(QuicAbortDirection abortDirection, long errorCode)
361361
362362 unsafe
363363 {
364- ThrowIfFailure ( MsQuicApi . Api . ApiTable ->StreamShutdown (
364+ ThrowHelper . ThrowIfMsQuicError ( MsQuicApi . Api . ApiTable ->StreamShutdown (
365365 _handle . QuicHandle ,
366366 flags ,
367367 ( ulong ) errorCode ) ) ;
@@ -376,7 +376,7 @@ public void CompleteWrites()
376376 {
377377 unsafe
378378 {
379- ThrowIfFailure ( MsQuicApi . Api . ApiTable ->StreamShutdown (
379+ ThrowHelper . ThrowIfMsQuicError ( MsQuicApi . Api . ApiTable ->StreamShutdown (
380380 _handle . QuicHandle ,
381381 QUIC_STREAM_SHUTDOWN_FLAGS . GRACEFUL ,
382382 default ) ) ;
@@ -397,7 +397,7 @@ private unsafe int HandleEventStartComplete(ref START_COMPLETE data)
397397 }
398398 else
399399 {
400- _startedTcs . TrySetException ( new MsQuicException ( data . Status ) ) ;
400+ _startedTcs . TrySetException ( ThrowHelper . GetExceptionForMsQuicStatus ( data . Status ) ) ;
401401 // TODO: aborted and exception type
402402 }
403403
@@ -445,12 +445,12 @@ private unsafe int HandleEventPeerSendShutdown()
445445 private unsafe int HandleEventPeerSendAborted ( ref PEER_SEND_ABORTED data )
446446 {
447447 _receiveBuffers . SetFinal ( ) ;
448- _receiveTcs . TrySetException ( new QuicStreamAbortedException ( ( long ) data . ErrorCode ) , final : true ) ;
448+ _receiveTcs . TrySetException ( ThrowHelper . GetStreamAbortedException ( ( long ) data . ErrorCode ) , final : true ) ;
449449 return QUIC_STATUS_SUCCESS ;
450450 }
451451 private unsafe int HandleEventPeerReceiveAborted ( ref PEER_RECEIVE_ABORTED data )
452452 {
453- _sendTcs . TrySetException ( new QuicStreamAbortedException ( ( long ) data . ErrorCode ) , final : true ) ;
453+ _sendTcs . TrySetException ( ThrowHelper . GetStreamAbortedException ( ( long ) data . ErrorCode ) , final : true ) ;
454454 return QUIC_STATUS_SUCCESS ;
455455 }
456456 private unsafe int HandleEventSendShutdownComplete ( ref SEND_SHUTDOWN_COMPLETE data )
@@ -466,7 +466,7 @@ private unsafe int HandleEventShutdownComplete(ref SHUTDOWN_COMPLETE data)
466466 {
467467 if ( data . ConnectionShutdown != 0 )
468468 {
469- Exception exception = data . ConnectionShutdownByApp != 0 && data . ConnectionClosedRemotely == 0 ? new QuicOperationAbortedException ( ) : new QuicConnectionAbortedException ( ( long ) data . ConnectionErrorCode ) ;
469+ Exception exception = data . ConnectionShutdownByApp != 0 && data . ConnectionClosedRemotely == 0 ? ThrowHelper . GetOperationAbortedException ( ) : ThrowHelper . GetConnectionAbortedException ( ( long ) data . ConnectionErrorCode ) ;
470470 _startedTcs . TrySetException ( exception ) ;
471471 _receiveTcs . TrySetException ( exception , final : true ) ;
472472 _sendTcs . TrySetException ( exception , final : true ) ;
@@ -559,7 +559,7 @@ public override async ValueTask DisposeAsync()
559559 else
560560 {
561561 // Abort the read side of the stream if it hasn't been fully consumed.
562- if ( _receiveTcs . TrySetException ( new QuicOperationAbortedException ( ) , final : true ) )
562+ if ( _receiveTcs . TrySetException ( ThrowHelper . GetOperationAbortedException ( ) , final : true ) )
563563 {
564564 StreamShutdown ( QUIC_STREAM_SHUTDOWN_FLAGS . ABORT_RECEIVE , _defaultErrorCode ) ;
565565 }
@@ -586,7 +586,7 @@ unsafe void StreamShutdown(QUIC_STREAM_SHUTDOWN_FLAGS flags, long errorCode)
586586 {
587587 if ( NetEventSource . Log . IsEnabled ( ) )
588588 {
589- NetEventSource . Error ( this , $ "{ this } StreamShutdown({ flags } ) failed: { MsQuicException . GetErrorCodeForStatus ( status ) } .") ;
589+ NetEventSource . Error ( this , $ "{ this } StreamShutdown({ flags } ) failed: { ThrowHelper . GetErrorMessageForStatus ( status ) } .") ;
590590 }
591591 }
592592 }
0 commit comments