Skip to content

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

Open
aisk wants to merge 17 commits into
python:mainfrom
aisk:windows-socket-sendfile
Open

gh-65920: Implement socket.sendfile with TransmitFile on Windows#112337
aisk wants to merge 17 commits into
python:mainfrom
aisk:windows-socket-sendfile

Conversation

@aisk

@aisk aisk commented Nov 23, 2023

Copy link
Copy Markdown
Member
  • 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: #102898 (comment)

@aisk aisk changed the title gh-65920: Windows socket sendfile gh-65920: imlement socket.sendfile with TransmitFile on Windows Nov 23, 2023
@erlend-aasland erlend-aasland requested a review from eryksun January 6, 2024 21:24
@erlend-aasland erlend-aasland changed the title gh-65920: imlement socket.sendfile with TransmitFile on Windows gh-65920: Implement socket.sendfile with TransmitFile on Windows Jan 6, 2024
Comment thread Misc/NEWS.d/next/Windows/2023-11-23-22-25-16.gh-issue-65920.6wWsHN.rst Outdated
…WsHN.rst

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Comment thread Lib/socket.py Outdated
@aisk

aisk commented Apr 24, 2024

Copy link
Copy Markdown
Member Author

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

@Archmonger

Copy link
Copy Markdown

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.

@imba-tjd

imba-tjd commented Dec 16, 2025

Copy link
Copy Markdown
Contributor

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)

@aisk

aisk commented Mar 1, 2026

Copy link
Copy Markdown
Member Author

@imba-tjd Thank you for your review, I found that we still need to call TransmitFile by chunk if the file is too large. Updated.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants