cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-65920: Implement `socket.sendfile` with `TransmitFile` on Windows

Open aisk opened this issue 2 years ago • 3 comments

  • Using the Overlapped.TransmitFile in _overlapped module to implement socket.sendfile;
  • Add Overlapped.getresultex to implement the timeout functionality, which have almost the same codes as exists Overlapped.getresult, just with diffenernt arguments. I split the Overlapped.getresult in 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

aisk avatar Nov 23 '23 14:11 aisk

Hi @eryksun , sorry to bother you, but can you help me review this PR when you have time? Thanks very much!

aisk avatar Apr 24 '24 16:04 aisk

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.

Archmonger avatar May 21 '25 00:05 Archmonger

~~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)

imba-tjd avatar Dec 16 '25 12:12 imba-tjd