-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Windows: Emulate MSG_PEEK by read #19777
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
fa5a289
Windows: Emulate MSG_PEEK by read
c2b5b44
fix format
fd85009
fix compiler warning
8972610
fix compilation issue
4aeaeae
more coverage is needed but still testing ci
544a1c8
Merge remote-tracking branch 'upstream/main' into peekWindows2
15fc820
fix format and increase coverage
4e60815
fix format
fe11b35
fix gcc
1534dcd
address PR feedack v1
3eb8880
address comments
f2fd1fb
fix spelling
72e8f20
fix format
db35fbf
add override keyword
16caa4f
another format fix
a479ef8
fix string buffer used in fuzzing
d3dd4d3
fix typo in fuzzer
23c6341
add override keyword
1c1223f
fixed another typo
abe8be2
remove unused parameters
31aee37
PR comments and tests
55361a3
add hint for mac compiler
320e370
Improve the copyOutToSlices method
soulxu f73213d
Merge branch 'main' into peekWindows2
soulxu a2e8799
address comment
soulxu d113f4c
type conversion for macos
soulxu 0c03750
correct the copyOutToSlices method
soulxu 52828ee
Merge branch 'main' into peekWindows2
soulxu 959170b
remove NOT_IMPLEMENTED_GCOVR_EXCL_LINE
soulxu d023827
Merge branch 'main' into peekWindows2
soulxu d2fe6e2
address comment
soulxu d673110
Merge branch 'main' into peekWindows2
soulxu fc5b188
address comment
soulxu 9ab00eb
Merge branch 'main' into peekWindows2
soulxu c100290
Merge branch 'main' into peekWindows2
soulxu 9ff8188
Merge branch 'main' into peekWindows2
soulxu a8db58b
Fix the peek size
soulxu 88311b1
Add fuzz test for copyOutToSlices
soulxu 84d3b81
fix format
soulxu 8b4acf3
address comments
soulxu 7792871
address comment
soulxu 843ca3c
Merge branch 'main' into peekWindows2
soulxu 4bf0aff
Merge branch 'main' into peekWindows3
soulxu cf83aad
fix copyOutToSlices
soulxu d789aae
remove useless log
soulxu 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 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -118,6 +118,43 @@ void OwnedImpl::copyOut(size_t start, uint64_t size, void* data) const { | |
ASSERT(size == 0); | ||
} | ||
|
||
uint64_t OwnedImpl::copyOutToSlices(uint64_t size, Buffer::RawSlice* dest_slices, | ||
uint64_t num_slice) const { | ||
uint64_t total_length_to_read = std::min(size, this->length()); | ||
uint64_t num_bytes_read = 0; | ||
uint64_t num_dest_slices_read = 0; | ||
uint64_t num_src_slices_read = 0; | ||
uint64_t dest_slice_offset = 0; | ||
uint64_t src_slice_offset = 0; | ||
while (num_dest_slices_read < num_slice && num_bytes_read < total_length_to_read) { | ||
const Slice& src_slice = slices_[num_src_slices_read]; | ||
const Buffer::RawSlice& dest_slice = dest_slices[num_dest_slices_read]; | ||
uint64_t left_to_read = total_length_to_read - num_bytes_read; | ||
uint64_t left_data_size_in_dst_slice = dest_slice.len_ - dest_slice_offset; | ||
uint64_t left_data_size_in_src_slice = src_slice.dataSize() - src_slice_offset; | ||
// The length to copy should be size of smallest in the source slice available size and | ||
// the dest slice available size. | ||
uint64_t length_to_copy = | ||
std::min(left_data_size_in_src_slice, std::min(left_data_size_in_dst_slice, left_to_read)); | ||
memcpy(static_cast<uint8_t*>(dest_slice.mem_) + dest_slice_offset, // NOLINT(safe-memcpy) | ||
src_slice.data() + src_slice_offset, length_to_copy); | ||
src_slice_offset = src_slice_offset + length_to_copy; | ||
dest_slice_offset = dest_slice_offset + length_to_copy; | ||
if (src_slice_offset == src_slice.dataSize()) { | ||
num_src_slices_read++; | ||
src_slice_offset = 0; | ||
} | ||
if (dest_slice_offset == dest_slice.len_) { | ||
num_dest_slices_read++; | ||
dest_slice_offset = 0; | ||
} | ||
ASSERT(src_slice_offset <= src_slice.dataSize()); | ||
ASSERT(dest_slice_offset <= dest_slice.len_); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add two assertions for defending. |
||
num_bytes_read += length_to_copy; | ||
} | ||
return num_bytes_read; | ||
} | ||
|
||
void OwnedImpl::drain(uint64_t size) { drainImpl(size); } | ||
|
||
void OwnedImpl::drainImpl(uint64_t size) { | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I correct the
length_to_copy
calculation.