gh-65920: Implement `socket.sendfile` with `TransmitFile` on Windows
- Using the
Overlapped.TransmitFilein_overlappedmodule to implementsocket.sendfile; - Add
Overlapped.getresultexto implement the timeout functionality, which have almost the same codes as existsOverlapped.getresult, just with diffenernt arguments. I split theOverlapped.getresultin to another function to share the codes.
And some thought on os.sendfile: https://github.com/python/cpython/issues/102898#issuecomment-1824554063
- Issue: gh-65920
Hi @eryksun , sorry to bother you, but can you help me review this PR when you have time? Thanks very much!
Bumping this PR.
The community (and myself) seem to feel it is very disjointed that sendfile support exists on *nix but not Windows, despite the plumbing already existing since Python 3.7.
~~If I'm reading correctly, the code didn't consider the situation where count >= 2^31 - 1.~~
see https://learn.microsoft.com/windows/win32/api/mswsock/nf-mswsock-transmitfile#remarks
The maximum number of bytes that can be transmitted using a single call to the TransmitFile function is 2,147,483,646
If an application needs to transmit a file larger than 2,147,483,646 bytes, then multiple calls to the TransmitFile function can be used with each call transferring no more than 2,147,483,646 bytes.
Setting the nNumberOfBytesToWrite parameter to zero for a file larger than 2,147,483,646 bytes will also fail since in this case the TransmitFile function will use the size of the file as the value for the number of bytes to transmit.
Never mind. There is a blocksize = min(count or fsize, 2 ** 30)