bpo-32622: Native sendfile on windows (#5565)

* Support sendfile on Windows Proactor event loop naively.
This commit is contained in:
Andrew Svetlov 2018-02-25 19:32:14 +03:00 committed by GitHub
parent 5fb632e831
commit a19fb3c6aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 431 additions and 93 deletions

View file

@ -4,6 +4,7 @@ import _overlapped
import _winapi
import errno
import math
import msvcrt
import socket
import struct
import weakref
@ -527,6 +528,27 @@ class IocpProactor:
return self._register(ov, conn, finish_connect)
def sendfile(self, sock, file, offset, count):
self._register_with_iocp(sock)
ov = _overlapped.Overlapped(NULL)
offset_low = offset & 0xffff_ffff
offset_high = (offset >> 32) & 0xffff_ffff
ov.TransmitFile(sock.fileno(),
msvcrt.get_osfhandle(file.fileno()),
offset_low, offset_high,
count, 0, 0)
def finish_sendfile(trans, key, ov):
try:
return ov.getresult()
except OSError as exc:
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
_overlapped.ERROR_OPERATION_ABORTED):
raise ConnectionResetError(*exc.args)
else:
raise
return self._register(ov, sock, finish_sendfile)
def accept_pipe(self, pipe):
self._register_with_iocp(pipe)
ov = _overlapped.Overlapped(NULL)