-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
gh-112341: Specify the exact file size if offset is non zero in socket.sendfile
#112342
Conversation
socket.sendfile
Is there an easy way to add tests for this? |
Thanks for the review, test case added. |
How does this relate to |
The problem this PR want to resolve is that, if we have a file with size 42, and want to send it to a socket from the start Because we do not specify the count parameter, The current codes in main branch missed the Then Modern systems which CPython supports with But I've tried to implement the So I think this is a bug and we should fix it. But, the is not the end of this story. I found that the And then the change in this PR is not a must to have. But I still feels like it's a bug, so we should fix it 😂. |
Thanks, @aisk, makes sense to me! cc. @serhiy-storchaka if he want's to take a look. I'm aiming for landing this in a couple of days. |
Could you try to compose a short NEWS entry for this? I'm unsure if we really need one; this feels like an implementation detail. |
@@ -360,7 +360,7 @@ def _sendfile_use_sendfile(self, file, offset=0, count=None): | |||
if not fsize: | |||
return 0 # empty file | |||
# Truncate to 1GiB to avoid OverflowError, see bpo-38319. | |||
blocksize = min(count or fsize, 2 ** 30) | |||
blocksize = min(count or fsize - offset, 2 ** 30) |
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.
What if offset >= fsize
?
Please add tests for offset == fsize
and offset > fsize
.
There are some discussions on the original issue #112341. I think this should not be treated as a bug, so I'm closing this. If anyone wants to discuss it further, we can reopen it. Still appreciate the review! |
I think this is a minor fix, so the news entry is not needed.