Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enum rename _FLAG --> _FLAGS to follow msquic naming.
  • Loading branch information
ManickaP committed Mar 12, 2021
commit e96522e5180e41831dbfd261949d78f4b6ccad5e
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal unsafe sealed class MsQuicApi
public SafeMsQuicRegistrationHandle Registration { get; }

// This is workaround for a bug in ILTrimmer.
// Withough these DynamicDependency attributes, .ctor() will be removed from the safe handles.
// Without these DynamicDependency attributes, .ctor() will be removed from the safe handles.
// Remove once fixed: https://github.com/mono/linker/issues/1660
[DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof(SafeMsQuicRegistrationHandle))]
[DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof(SafeMsQuicConfigurationHandle))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
{
internal enum QUIC_EXECUTION_PROFILE : uint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really NOT the style guy but in some other places we made the names C# friendly.

internal enum SecurityStatusPalErrorCode
{
NotSet = 0,
OK,
ContinueNeeded,
CompleteNeeded,

and we use int unless uint is really needed (even if underlying C is uint)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't change the naming scheme in this PR, that's too revolutionary 😃.
We might change it in a separate one or we might go a different direction if we chose to generate the interop.

{
QUIC_EXECUTION_PROFILE_LOW_LATENCY, // Default
QUIC_EXECUTION_PROFILE_LOW_LATENCY, // Default
QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT,
QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER,
QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME
Expand All @@ -18,36 +18,48 @@ internal enum QUIC_CREDENTIAL_TYPE : uint
HASH_STORE,
CONTEXT,
FILE,
STUB_NULL = 0xF0000000 // pass as server cert to stubtls implementation
FILE_PROTECTED,
STUB_NULL = 0xF0000000 // Pass as server cert to stubtls implementation
}

[Flags]
internal enum QUIC_CREDENTIAL_FLAGS : uint
{
NONE = 0,
CLIENT = 1, // lack of client flag indicates server.
LOAD_ASYNCHRONOUS = 2,
NO_CERTIFICATE_VALIDATION = 4,
ENABLE_OCSP = 8
NONE = 0x00000000,
CLIENT = 0x00000001, // Lack of client flag indicates server.
LOAD_ASYNCHRONOUS = 0x00000002,
NO_CERTIFICATE_VALIDATION = 0x00000004,
ENABLE_OCSP = 0x00000008, // Schannel only currently
INDICATE_CERTIFICATE_RECEIVED = 0x00000010,
DEFER_CERTIFICATE_VALIDATION = 0x00000020, // Schannel only currently
REQUIRE_CLIENT_AUTHENTICATION = 0x00000040, // Schannel only currently
USE_TLS_BUILTIN_CERTIFICATE_VALIDATION = 0x00000080
}

[Flags]
internal enum QUIC_CONNECTION_SHUTDOWN_FLAG : uint
internal enum QUIC_CONNECTION_SHUTDOWN_FLAGS : uint
{
NONE = 0x0,
SILENT = 0x1
}

internal enum QUIC_SERVER_RESUMPTION_LEVEL : uint
{
NO_RESUME,
RESUME_ONLY,
RESUME_AND_ZERORTT
}

[Flags]
internal enum QUIC_STREAM_OPEN_FLAG : uint
internal enum QUIC_STREAM_OPEN_FLAGS : uint
{
NONE = 0,
UNIDIRECTIONAL = 0x1,
ZERO_RTT = 0x2,
}

[Flags]
internal enum QUIC_STREAM_START_FLAG : uint
internal enum QUIC_STREAM_START_FLAGS : uint
{
NONE = 0,
FAIL_BLOCKED = 0x1,
Expand All @@ -56,7 +68,7 @@ internal enum QUIC_STREAM_START_FLAG : uint
}

[Flags]
internal enum QUIC_STREAM_SHUTDOWN_FLAG : uint
internal enum QUIC_STREAM_SHUTDOWN_FLAGS : uint
{
NONE = 0,
GRACEFUL = 0x1,
Expand All @@ -67,15 +79,15 @@ internal enum QUIC_STREAM_SHUTDOWN_FLAG : uint
}

[Flags]
internal enum QUIC_RECEIVE_FLAG : uint
internal enum QUIC_RECEIVE_FLAGS : uint
{
NONE = 0,
ZERO_RTT = 0x1,
FIN = 0x02
}

[Flags]
internal enum QUIC_SEND_FLAG : uint
internal enum QUIC_SEND_FLAGS : uint
{
NONE = 0,
ALLOW_0_RTT = 0x00000001,
Expand Down Expand Up @@ -192,11 +204,4 @@ internal enum QUIC_STREAM_EVENT : uint
SHUTDOWN_COMPLETE = 7,
IDEAL_SEND_BUFFER_SIZE = 8,
}

internal enum QUIC_SERVER_RESUMPTION_LEVEL : byte
{
NO_RESUME,
RESUME_ONLY,
RESUME_AND_ZERORTT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ internal struct ConnectionEvent
internal bool ShutdownTimedOut => Data.ShutdownComplete.TimedOut;
internal ushort BiDirectionalCount => Data.StreamsAvailable.BiDirectionalCount;
internal ushort UniDirectionalCount => Data.StreamsAvailable.UniDirectionalCount;
internal QUIC_STREAM_OPEN_FLAG StreamFlags => (QUIC_STREAM_OPEN_FLAG)Data.StreamStarted.Flags;
internal QUIC_STREAM_OPEN_FLAGS StreamFlags => (QUIC_STREAM_OPEN_FLAGS)Data.StreamStarted.Flags;
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
Expand Down Expand Up @@ -528,19 +528,6 @@ internal struct Settings
internal byte BitField;
}

internal enum SettingsBitField : byte
{
SendBufferingEnabled = 1,
PacingEnabled = 1 << 1,
MigrationEnabled = 1 << 2,
DatagramReceiveEnabled = 1 << 3,

// single enum field, 2 bits.
NoResume = QUIC_SERVER_RESUMPTION_LEVEL.NO_RESUME << 4,
ResumeOnly = QUIC_SERVER_RESUMPTION_LEVEL.RESUME_ONLY << 4,
ResumeAndZeroRtt = QUIC_SERVER_RESUMPTION_LEVEL.RESUME_AND_ZERORTT << 4
}

[Flags]
internal enum SettingsFlags : ulong
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ internal override async ValueTask<QuicStreamProvider> AcceptStreamAsync(Cancella
internal override QuicStreamProvider OpenUnidirectionalStream()
{
ThrowIfDisposed();
return new MsQuicStream(_state.Handle, QUIC_STREAM_OPEN_FLAG.UNIDIRECTIONAL);
return new MsQuicStream(_state.Handle, QUIC_STREAM_OPEN_FLAGS.UNIDIRECTIONAL);
}

internal override QuicStreamProvider OpenBidirectionalStream()
{
ThrowIfDisposed();
return new MsQuicStream(_state.Handle, QUIC_STREAM_OPEN_FLAG.NONE);
return new MsQuicStream(_state.Handle, QUIC_STREAM_OPEN_FLAGS.NONE);
}

internal override long GetRemoteAvailableUnidirectionalStreamCount()
Expand Down Expand Up @@ -271,7 +271,7 @@ internal override ValueTask ConnectAsync(CancellationToken cancellationToken = d
}

private ValueTask ShutdownAsync(
QUIC_CONNECTION_SHUTDOWN_FLAG Flags,
QUIC_CONNECTION_SHUTDOWN_FLAGS Flags,
long ErrorCode)
{
Debug.Assert(!_state.ShutdownTcs.Task.IsCompleted);
Expand Down Expand Up @@ -375,7 +375,7 @@ internal override ValueTask CloseAsync(long errorCode, CancellationToken cancell
{
ThrowIfDisposed();

return ShutdownAsync(QUIC_CONNECTION_SHUTDOWN_FLAG.NONE, errorCode);
return ShutdownAsync(QUIC_CONNECTION_SHUTDOWN_FLAGS.NONE, errorCode);
}

private void ThrowIfDisposed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ private sealed class State
}

// inbound.
internal MsQuicStream(SafeMsQuicStreamHandle streamHandle, QUIC_STREAM_OPEN_FLAG flags)
internal MsQuicStream(SafeMsQuicStreamHandle streamHandle, QUIC_STREAM_OPEN_FLAGS flags)
{
_state.Handle = streamHandle;
_canRead = true;
_canWrite = !flags.HasFlag(QUIC_STREAM_OPEN_FLAG.UNIDIRECTIONAL);
_canWrite = !flags.HasFlag(QUIC_STREAM_OPEN_FLAGS.UNIDIRECTIONAL);
_started = true;

_stateHandle = GCHandle.Alloc(_state);
Expand All @@ -88,11 +88,11 @@ internal MsQuicStream(SafeMsQuicStreamHandle streamHandle, QUIC_STREAM_OPEN_FLAG
}

// outbound.
internal MsQuicStream(SafeMsQuicConnectionHandle connection, QUIC_STREAM_OPEN_FLAG flags)
internal MsQuicStream(SafeMsQuicConnectionHandle connection, QUIC_STREAM_OPEN_FLAGS flags)
{
Debug.Assert(connection != null);

_canRead = !flags.HasFlag(QUIC_STREAM_OPEN_FLAG.UNIDIRECTIONAL);
_canRead = !flags.HasFlag(QUIC_STREAM_OPEN_FLAGS.UNIDIRECTIONAL);
_canWrite = true;

_stateHandle = GCHandle.Alloc(_state);
Expand All @@ -107,7 +107,7 @@ internal MsQuicStream(SafeMsQuicConnectionHandle connection, QUIC_STREAM_OPEN_FL

QuicExceptionHelpers.ThrowIfFailed(status, "Failed to open stream to peer.");

status = MsQuicApi.Api.StreamStartDelegate(_state.Handle, (uint)QUIC_STREAM_START_FLAG.ASYNC);
status = MsQuicApi.Api.StreamStartDelegate(_state.Handle, (uint)QUIC_STREAM_START_FLAGS.ASYNC);
QuicExceptionHelpers.ThrowIfFailed(status, "Could not start stream.");
}
catch
Expand Down Expand Up @@ -153,7 +153,7 @@ internal override async ValueTask WriteAsync(ReadOnlySequence<byte> buffers, boo

using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);

await SendReadOnlySequenceAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
await SendReadOnlySequenceAsync(buffers, endStream ? QUIC_SEND_FLAGS.FIN : QUIC_SEND_FLAGS.NONE).ConfigureAwait(false);

HandleWriteCompletedState();
}
Expand All @@ -168,7 +168,7 @@ internal override async ValueTask WriteAsync(ReadOnlyMemory<ReadOnlyMemory<byte>
ThrowIfDisposed();

using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);
await SendReadOnlyMemoryListAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
await SendReadOnlyMemoryListAsync(buffers, endStream ? QUIC_SEND_FLAGS.FIN : QUIC_SEND_FLAGS.NONE).ConfigureAwait(false);

HandleWriteCompletedState();
}
Expand All @@ -179,7 +179,7 @@ internal override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool e

using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);

await SendReadOnlyMemoryAsync(buffer, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
await SendReadOnlyMemoryAsync(buffer, endStream ? QUIC_SEND_FLAGS.FIN : QUIC_SEND_FLAGS.NONE).ConfigureAwait(false);

HandleWriteCompletedState();
}
Expand Down Expand Up @@ -338,7 +338,7 @@ internal override void AbortRead(long errorCode)
_state.ReadState = ReadState.Aborted;
}

StartShutdown(QUIC_STREAM_SHUTDOWN_FLAG.ABORT_RECV, errorCode);
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAGS.ABORT_RECV, errorCode);
}

internal override void AbortWrite(long errorCode)
Expand All @@ -361,10 +361,10 @@ internal override void AbortWrite(long errorCode)
_state.ShutdownWriteCompletionSource.SetException(new QuicStreamAbortedException("Shutdown was aborted.", errorCode));
}

StartShutdown(QUIC_STREAM_SHUTDOWN_FLAG.ABORT_SEND, errorCode);
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAGS.ABORT_SEND, errorCode);
}

private void StartShutdown(QUIC_STREAM_SHUTDOWN_FLAG flags, long errorCode)
private void StartShutdown(QUIC_STREAM_SHUTDOWN_FLAGS flags, long errorCode)
{
uint status = MsQuicApi.Api.StreamShutdownDelegate(_state.Handle, (uint)flags, errorCode);
QuicExceptionHelpers.ThrowIfFailed(status, "StreamShutdown failed.");
Expand Down Expand Up @@ -399,7 +399,7 @@ internal override async ValueTask ShutdownWriteCompleted(CancellationToken cance
internal override void Shutdown()
{
ThrowIfDisposed();
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAG.GRACEFUL, errorCode: 0);
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAGS.GRACEFUL, errorCode: 0);
}

// TODO consider removing sync-over-async with blocking calls.
Expand Down Expand Up @@ -734,14 +734,14 @@ private static void CleanupSendState(State state)
// TODO prevent overlapping sends or consider supporting it.
private unsafe ValueTask SendReadOnlyMemoryAsync(
ReadOnlyMemory<byte> buffer,
QUIC_SEND_FLAG flags)
QUIC_SEND_FLAGS flags)
{
if (buffer.IsEmpty)
{
if ((flags & QUIC_SEND_FLAG.FIN) == QUIC_SEND_FLAG.FIN)
if ((flags & QUIC_SEND_FLAGS.FIN) == QUIC_SEND_FLAGS.FIN)
{
// Start graceful shutdown sequence if passed in the fin flag and there is an empty buffer.
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAG.GRACEFUL, errorCode: 0);
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAGS.GRACEFUL, errorCode: 0);
}
return default;
}
Expand Down Expand Up @@ -777,14 +777,14 @@ private unsafe ValueTask SendReadOnlyMemoryAsync(

private unsafe ValueTask SendReadOnlySequenceAsync(
ReadOnlySequence<byte> buffers,
QUIC_SEND_FLAG flags)
QUIC_SEND_FLAGS flags)
{
if (buffers.IsEmpty)
{
if ((flags & QUIC_SEND_FLAG.FIN) == QUIC_SEND_FLAG.FIN)
if ((flags & QUIC_SEND_FLAGS.FIN) == QUIC_SEND_FLAGS.FIN)
{
// Start graceful shutdown sequence if passed in the fin flag and there is an empty buffer.
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAG.GRACEFUL, errorCode: 0);
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAGS.GRACEFUL, errorCode: 0);
}
return default;
}
Expand Down Expand Up @@ -838,14 +838,14 @@ private unsafe ValueTask SendReadOnlySequenceAsync(

private unsafe ValueTask SendReadOnlyMemoryListAsync(
ReadOnlyMemory<ReadOnlyMemory<byte>> buffers,
QUIC_SEND_FLAG flags)
QUIC_SEND_FLAGS flags)
{
if (buffers.IsEmpty)
{
if ((flags & QUIC_SEND_FLAG.FIN) == QUIC_SEND_FLAG.FIN)
if ((flags & QUIC_SEND_FLAGS.FIN) == QUIC_SEND_FLAGS.FIN)
{
// Start graceful shutdown sequence if passed in the fin flag and there is an empty buffer.
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAG.GRACEFUL, errorCode: 0);
StartShutdown(QUIC_STREAM_SHUTDOWN_FLAGS.GRACEFUL, errorCode: 0);
}
return default;
}
Expand Down