Skip to content

Commit d1337e9

Browse files
committed
Post merge fixes
1 parent 0da5ce2 commit d1337e9

5 files changed

Lines changed: 19 additions & 24 deletions

File tree

src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private MsQuicApi(QUIC_API_TABLE* apiTable)
4141
};
4242

4343
QUIC_HANDLE* handle;
44-
ThrowIfFailure(ApiTable->RegistrationOpen(&cfg, &handle), "RegistrationOpen failed");
44+
ThrowHelper.ThrowIfMsQuicError(ApiTable->RegistrationOpen(&cfg, &handle), "RegistrationOpen failed");
4545

4646
Registration = new MsQuicSafeHandle(handle, apiTable->RegistrationClose, SafeHandleType.Registration);
4747
}

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,13 @@ private unsafe int HandleEventConnected(ref CONNECTED_DATA data)
453453
private unsafe int HandleEventShutdownInitiatedByTransport(ref SHUTDOWN_INITIATED_BY_TRANSPORT_DATA data)
454454
{
455455
_connectedTcs.TrySetException(ThrowHelper.GetExceptionForMsQuicStatus(data.Status));
456-
_acceptQueue.Writer.TryComplete(ExceptionDispatchInfo.SetCurrentStackTrace(ThrowHelper.GetConnectionAbortedException(_abortErrorCode)));
456+
// TODO: we should differentiate transport from app since the error code here is bogus.
457+
_acceptQueue.Writer.TryComplete(ExceptionDispatchInfo.SetCurrentStackTrace(ThrowHelper.GetConnectionAbortedException(0)));
457458
return QUIC_STATUS_SUCCESS;
458459
}
459460
private unsafe int HandleEventShutdownInitiatedByPeer(ref SHUTDOWN_INITIATED_BY_PEER_DATA data)
460461
{
461-
_acceptQueue.Writer.TryComplete(ExceptionDispatchInfo.SetCurrentStackTrace(ThrowHelper.GetConnectionAbortedException(_abortErrorCode)));
462+
_acceptQueue.Writer.TryComplete(ExceptionDispatchInfo.SetCurrentStackTrace(ThrowHelper.GetConnectionAbortedException((long)data.ErrorCode)));
462463
return QUIC_STATUS_SUCCESS;
463464
}
464465
private unsafe int HandleEventShutdownComplete(ref SHUTDOWN_COMPLETE_DATA data)

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum QuicError
1414
Success,
1515

1616
/// <summary>
17-
/// An internal implementation error has occured.
17+
/// An internal implementation error has occurred.
1818
/// </summary>
1919
InternalError,
2020

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/libraries/System.Net.Quic/tests/FunctionalTests/QuicStreamTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,6 @@ await RunClientServer(
553553
[Fact]
554554
public async Task WritePreCanceled_Throws()
555555
{
556-
// Corresponds to default error code in client connection settings.
557-
const long expectedErrorCode = 123456;
558-
559556
await RunClientServer(
560557
clientFunction: async connection =>
561558
{
@@ -584,9 +581,6 @@ await RunClientServer(
584581
[Fact]
585582
public async Task WriteCanceled_NextWriteThrows()
586583
{
587-
// Corresponds to default error code in client connection settings.
588-
const long expectedErrorCode = 123456;
589-
590584
await RunClientServer(
591585
clientFunction: async connection =>
592586
{

0 commit comments

Comments
 (0)