Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for os.sendfile for Windows #102898

Open
KhazAkar opened this issue Mar 22, 2023 · 1 comment
Open

Support for os.sendfile for Windows #102898

KhazAkar opened this issue Mar 22, 2023 · 1 comment
Labels
extension-modules C modules in the Modules dir OS-windows topic-IO type-feature A feature request or enhancement

Comments

@KhazAkar
Copy link

KhazAkar commented Mar 22, 2023

Feature or enhancement

Currently, only POSIX operating systems have support for sendfile in python, but not Windows (or at least not on the same level, more about that later). There's a catch - windows also have support for this kind of functionality, called TransmitFile:
https://learn.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-transmitfile

Pitch

Having this feature outside of asyncio (here it currently resides when using sock_sendfile, as link in "previous discussion" states) would help in closing the gap between what's supported on Windows and on POSIX OSes like macOS or Linux.
Basic support for things like overlapped I/O (Windows acronym for asynchronous I/O) currently exists in lower level modules, like undocumented _overlapped module. Having this exposed in more user-friendly manner would give python better feature parity between various Tier-1 operating systems.

Previous discussion

https://discuss.python.org/t/support-for-os-sendfile-for-windows/25020

@KhazAkar KhazAkar added the type-feature A feature request or enhancement label Mar 22, 2023
@aisk
Copy link
Member

aisk commented Nov 23, 2023

I have a try on this, but found that there are some gaps between the *nix sendfile and Windows TransmitFile:

  • If count + offset > file_size, sendfile will just send the rest of the file, and returns the byte which have been sent. The TransmitFile will raise a Windows error (and don't know how many bytes have been sent).
  • TransmitFile use the overlapped IO stuff to make the timeout, and ignores the SO_SNDTIMEO socket option. Although Python don't use it to make timeout.

And the os.sendfile is just low level API, and most people are just using socket.sendfile in their codes.

So I think just implement the socket.sendfile via TransmitFile is a better idea, which already have a issue: #65920 , and if someone want a low level API, he can just using the Overlapped.TransmitFile.

cc @eryksun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir OS-windows topic-IO type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants