Skip to content
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

VIS-6891 Fix ReadAsync for NetworkStream #48

Merged
merged 1 commit into from
Apr 27, 2024

Conversation

amakhno
Copy link

@amakhno amakhno commented Apr 27, 2024

Problem

ReadAsync may read less data than expected if a buffer hasn't been filled yet.

Happens when the stream is a network stream

Solution

We can simply use CopyAsync there

using var memoryStream = new MemoryStream(buffer);
using var memoryStream = new MemoryStream(capacity: (int)stream.Length);
// 81_920 is a default value for the buffer size
await stream.CopyToAsync(memoryStream, 81_920, cancellationToken).ConfigureAwait(false);

Choose a reason for hiding this comment

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

зачем явно задавать это значение, если оно равно дефолтному?
может вызывать stream.CopyToAsync(memoryStream) ?

Copy link
Author

Choose a reason for hiding this comment

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

Нужно передать cancellationToken, и там нет сигнатуры без передачи buffer size, но с токеном

@amakhno amakhno merged commit e1c63e0 into softsmile Apr 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants