diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-06-15 11:24:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-15 11:24:16 (GMT) |
commit | bb07321c6a7e1cbe597c3fc5fa275a85d0f50acb (patch) | |
tree | ef29f1c36721280d5fe675bfaf6fb8bbf57981b1 | |
parent | 3fde750cc4e4057076650a92946ec1d492464799 (diff) | |
download | cpython-bb07321c6a7e1cbe597c3fc5fa275a85d0f50acb.zip cpython-bb07321c6a7e1cbe597c3fc5fa275a85d0f50acb.tar.gz cpython-bb07321c6a7e1cbe597c3fc5fa275a85d0f50acb.tar.bz2 |
bpo-37279: Fix asyncio sendfile support when extra data are sent in fallback mode. (GH-14075)
(cherry picked from commit ef2152354f03a165c5e3adb53e2276934fabd50a)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
-rw-r--r-- | Lib/asyncio/base_events.py | 4 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_sendfile.py | 3 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst | 2 |
3 files changed, 6 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index e002539..90de858 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -861,7 +861,7 @@ class BaseEventLoop(events.AbstractEventLoop): read = await self.run_in_executor(None, file.readinto, view) if not read: break # EOF - await self.sock_sendall(sock, view) + await self.sock_sendall(sock, view[:read]) total_sent += read return total_sent finally: @@ -1145,7 +1145,7 @@ class BaseEventLoop(events.AbstractEventLoop): if not read: return total_sent # EOF await proto.drain() - transp.write(view) + transp.write(view[:read]) total_sent += read finally: if total_sent > 0 and hasattr(file, 'seek'): diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index f148fe2..3b7f784 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -86,7 +86,8 @@ class MyProto(asyncio.Protocol): class SendfileBase: - DATA = b"SendfileBaseData" * (1024 * 8) # 128 KiB + # 128 KiB plus small unaligned to buffer chunk + DATA = b"SendfileBaseData" * (1024 * 8 + 1) # Reduce socket buffer size to test on relative small data sets. BUF_SIZE = 4 * 1024 # 4 KiB diff --git a/Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst b/Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst new file mode 100644 index 0000000..d740b9b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst @@ -0,0 +1,2 @@ +Fix asyncio sendfile support when sendfile sends extra data in fallback +mode. |