Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-112341: Specify the exact file size if offset is non zero insocket.sendfile#112342

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
aisk wants to merge4 commits intopython:mainfromaisk:fix-blocksize-in-sendfile
Closed
Show file tree
Hide file tree
Changes fromall commits
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
2 changes: 1 addition & 1 deletionLib/socket.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)

Choose a reason for hiding this comment

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

What ifoffset >= fsize?

Please add tests foroffset == fsize andoffset > fsize.

timeout = self.gettimeout()
if timeout == 0:
raise ValueError("non-blocking sockets are not supported")
Expand Down
23 changes: 23 additions & 0 deletionsLib/test/test_socket.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import unittest
from unittest import mock
from test import support
from test.support import os_helper
from test.support import socket_helper
Expand DownExpand Up@@ -6433,6 +6434,28 @@ class SendfileUsingSendfileTest(SendfileUsingSendTest):
def meth_from_sock(self, sock):
return getattr(sock, "_sendfile_use_sendfile")

def _test_blocksize(self):
address = self.serv.getsockname()
file = open(os_helper.TESTFN, 'rb')
with socket.create_connection(address) as sock, file as file:
meth = self.meth_from_sock(sock)
with mock.patch('os.sendfile', wraps=os.sendfile) as mocked:
sent = meth(file, offset=10)
self.assertEqual(mocked.call_count, 2)
# blocksize is the blocksize argument in first call.
blocksize = mocked.call_args_list[0][0][3]
self.assertEqual(blocksize, self.FILESIZE - 10)
self.assertEqual(sent, self.FILESIZE - 10)
self.assertEqual(file.tell(), self.FILESIZE)

def test_blocksize(self):
# gh-112341: Check whether the blocksize is exactly fsize - offset if
# count is not specified when calling os.sendfile.
conn = self.accept_conn()
data = self.recv_data(conn)
self.assertEqual(len(data), self.FILESIZE - 10)
self.assertEqual(data, self.FILEDATA[10:])


@unittest.skipUnless(HAVE_SOCKET_ALG, 'AF_ALG required')
class LinuxKernelCryptoAPI(unittest.TestCase):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp