-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Merge several version of MsQuicStream SendAsync code #68772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9dd028f
Merge several version of MsQuicStream SendAsync code
rzikm d5feac5
Use shared MsQuicBuffers struct
rzikm 4589cbc
Minor changes
rzikm 491ce39
Fixes after rebase
rzikm faf5e8b
Code review feedback
rzikm 668b81f
Use static lambdas instead of adapter structs
rzikm de2b5d2
Minor change
rzikm 7247995
fixup! Minor change
rzikm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -39,35 +39,94 @@ private void FreeNativeMemory() | |||
| NativeMemory.Free(buffers); | ||||
| } | ||||
|
|
||||
| private void Reserve(int count) | ||||
| { | ||||
| if (_handles.Length < count) | ||||
| { | ||||
| _handles = new MemoryHandle[count]; | ||||
| FreeNativeMemory(); | ||||
| _buffers = (QUIC_BUFFER*)NativeMemory.Alloc((nuint)count, (nuint)sizeof(QUIC_BUFFER)); | ||||
| } | ||||
| } | ||||
|
|
||||
| private void SetBuffer(int index, ReadOnlyMemory<byte> buffer) | ||||
| { | ||||
| MemoryHandle handle = buffer.Pin(); | ||||
|
|
||||
| _handles[index] = handle; | ||||
| _buffers[index].Buffer = (byte*)handle.Pointer; | ||||
| _buffers[index].Length = (uint)buffer.Length; | ||||
| } | ||||
|
|
||||
| /// <summary> | ||||
| /// The method initializes QUIC_BUFFER* with data from inputs, converted via toBuffer. | ||||
| /// Initializes QUIC_BUFFER* with data from inputs, converted via toBuffer. | ||||
| /// Note that the struct either needs to be freshly created via new or previously cleaned up with Reset. | ||||
| /// </summary> | ||||
| /// <param name="inputs">Inputs to get their byte array, pin them and pepare them to be passed to MsQuic as QUIC_BUFFER*.</param> | ||||
| /// <param name="toBuffer">Method extracting byte array from the inputs, e.g. applicationProtocol.Protocol.</param> | ||||
| /// <typeparam name="T">The type of the inputs.</typeparam> | ||||
| public void Initialize<T>(IList<T> inputs, Func<T, ReadOnlyMemory<byte>> toBuffer) | ||||
| { | ||||
| if (_handles.Length < inputs.Count) | ||||
| Reserve(inputs.Count); | ||||
| _count = inputs.Count; | ||||
rzikm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| for (int i = 0; i < inputs.Count; ++i) | ||||
| { | ||||
| _handles = new MemoryHandle[inputs.Count]; | ||||
| ReadOnlyMemory<byte> buffer = toBuffer(inputs[i]); | ||||
| SetBuffer(i, buffer); | ||||
| } | ||||
| if (_count < inputs.Count) | ||||
| } | ||||
|
|
||||
| /// <summary> | ||||
| /// Initializes QUIC_BUFFER* with the provided buffer. | ||||
| /// Note that the struct either needs to be freshly created via new or previously cleaned up with Reset. | ||||
| /// </summary> | ||||
| /// <param name="buffer">Buffer to be passed to MsQuic as QUIC_BUFFER*.</param> | ||||
| public void Initialize(ReadOnlyMemory<byte> buffer) | ||||
| { | ||||
| Reserve(1); | ||||
| _count = 1; | ||||
| SetBuffer(0, buffer); | ||||
| } | ||||
|
|
||||
| /// <summary> | ||||
| /// Initializes QUIC_BUFFER* with the provided buffers. | ||||
| /// Note that the struct either needs to be freshly created via new or previously cleaned up with Reset. | ||||
| /// </summary> | ||||
| /// <param name="buffers">Buffers to be passed to MsQuic as QUIC_BUFFER*.</param> | ||||
| public void Initialize(ReadOnlySequence<byte> buffers) | ||||
| { | ||||
| int count = 0; | ||||
| foreach (ReadOnlyMemory<byte> _ in buffers) | ||||
| { | ||||
| FreeNativeMemory(); | ||||
| _buffers = (QUIC_BUFFER*)NativeMemory.Alloc((nuint)sizeof(QUIC_BUFFER), (nuint)inputs.Count); | ||||
| ++count; | ||||
| } | ||||
|
|
||||
| _count = inputs.Count; | ||||
| Reserve(count); | ||||
| _count = count; | ||||
| count = 0; | ||||
rzikm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| for (int i = 0; i < inputs.Count; ++i) | ||||
| foreach (ReadOnlyMemory<byte> buffer in buffers) | ||||
| { | ||||
| ReadOnlyMemory<byte> buffer = toBuffer(inputs[i]); | ||||
| MemoryHandle handle = buffer.Pin(); | ||||
| SetBuffer(count, buffer); | ||||
| ++count; | ||||
rzikm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| } | ||||
| } | ||||
|
|
||||
| _handles[i] = handle; | ||||
| _buffers[i].Buffer = (byte*)handle.Pointer; | ||||
| _buffers[i].Length = (uint)buffer.Length; | ||||
| /// <summary> | ||||
| /// Initializes QUIC_BUFFER* with the provided buffers. | ||||
| /// Note that the struct either needs to be freshly created via new or previously cleaned up with Reset. | ||||
| /// </summary> | ||||
| /// <param name="buffers">Buffers to be passed to MsQuic as QUIC_BUFFER*.</param> | ||||
| public void Initialize(ReadOnlyMemory<ReadOnlyMemory<byte>> buffers) | ||||
| { | ||||
| int count = buffers.Length; | ||||
| Reserve(count); | ||||
| _count = count; | ||||
|
||||
| _count = count; |
rzikm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rzikm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.