summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py7
-rw-r--r--Lib/asyncio/constants.py4
2 files changed, 9 insertions, 2 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index a0243f5..ffd2513 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -800,7 +800,10 @@ class BaseEventLoop(events.AbstractEventLoop):
async def _sock_sendfile_fallback(self, sock, file, offset, count):
if offset:
file.seek(offset)
- blocksize = min(count, 16384) if count else 16384
+ blocksize = (
+ min(count, constants.SENDFILE_FALLBACK_READBUFFER_SIZE)
+ if count else constants.SENDFILE_FALLBACK_READBUFFER_SIZE
+ )
buf = bytearray(blocksize)
total_sent = 0
try:
@@ -810,7 +813,7 @@ class BaseEventLoop(events.AbstractEventLoop):
if blocksize <= 0:
break
view = memoryview(buf)[:blocksize]
- read = file.readinto(view)
+ read = await self.run_in_executor(None, file.readinto, view)
if not read:
break # EOF
await self.sock_sendall(sock, view)
diff --git a/Lib/asyncio/constants.py b/Lib/asyncio/constants.py
index 739b0a7..d7ba496 100644
--- a/Lib/asyncio/constants.py
+++ b/Lib/asyncio/constants.py
@@ -14,6 +14,10 @@ DEBUG_STACK_DEPTH = 10
# Number of seconds to wait for SSL handshake to complete
SSL_HANDSHAKE_TIMEOUT = 10.0
+# Used in sendfile fallback code. We use fallback for platforms
+# that don't support sendfile, or for TLS connections.
+SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 256
+
# The enum should be here to break circular dependencies between
# base_events and sslproto
class _SendfileMode(enum.Enum):