Commit ef215235 authored by Andrew Svetlov's avatar Andrew Svetlov Committed by GitHub

bpo-37279: Fix asyncio sendfile support when extra data are sent in fallback mode. (GH-14075)

parent 7efc526e
...@@ -861,7 +861,7 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -861,7 +861,7 @@ class BaseEventLoop(events.AbstractEventLoop):
read = await self.run_in_executor(None, file.readinto, view) read = await self.run_in_executor(None, file.readinto, view)
if not read: if not read:
break # EOF break # EOF
await self.sock_sendall(sock, view) await self.sock_sendall(sock, view[:read])
total_sent += read total_sent += read
return total_sent return total_sent
finally: finally:
...@@ -1145,7 +1145,7 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -1145,7 +1145,7 @@ class BaseEventLoop(events.AbstractEventLoop):
if not read: if not read:
return total_sent # EOF return total_sent # EOF
await proto.drain() await proto.drain()
transp.write(view) transp.write(view[:read])
total_sent += read total_sent += read
finally: finally:
if total_sent > 0 and hasattr(file, 'seek'): if total_sent > 0 and hasattr(file, 'seek'):
......
...@@ -86,7 +86,8 @@ class MyProto(asyncio.Protocol): ...@@ -86,7 +86,8 @@ class MyProto(asyncio.Protocol):
class SendfileBase: 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. # Reduce socket buffer size to test on relative small data sets.
BUF_SIZE = 4 * 1024 # 4 KiB BUF_SIZE = 4 * 1024 # 4 KiB
......
Fix asyncio sendfile support when sendfile sends extra data in fallback
mode.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment