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

Implement sendfile support. #228

Open
1st1 opened this issue Feb 15, 2019 · 2 comments
Open

Implement sendfile support. #228

1st1 opened this issue Feb 15, 2019 · 2 comments
Labels
help wanted missing feature a feature of vanilla asyncio is not implemented in uvloop

Comments

@1st1
Copy link
Member

1st1 commented Feb 15, 2019

Specifically two event loop methods are still missing:

  • loop.sock_sendfile(..)
  • loop.sendfile(..)

Both were added to asyncio 3.7.

@1st1 1st1 added the missing feature a feature of vanilla asyncio is not implemented in uvloop label Feb 15, 2019
@jlaine
Copy link
Contributor

jlaine commented Feb 17, 2019

To clarify the requirement here: is the plan to leverage some support from libuv or is this a matter of replicating the code from vanilla asyncio?

The only reference to sendfile I seem to find in libuv is:

http://docs.libuv.org/en/v1.x/fs.html#c.uv_fs_sendfile

@1st1
Copy link
Member Author

1st1 commented Feb 17, 2019

Unfortunately, the libuv's sendfile implementation is just a thin wrapper over the "sendfile" system call. I.e. uv_fs_sendfile() is not integrated with uv_tcp_t handles, so it's very similar to Python's os.sendfile(). This means that yes, what we'll need to do is similar to vanilla asyncio, and I think that using os.sendfile() should be easier for us (will ensure same error types/messages as in asyncio).

In terms of the actual implementation: first we'll need a loop.sock_sendfile() method, which should be relatively simple to implement. This should probably be the first PR.

The second PR should add loop.sendfile(). This one is more tricky; we'll need to:

  • use uv_poll_t handles to temporary monitor read activity for uv_tcp_t and uv_pipe_t handles;

  • replicate asyncio's logic with pausing and resuming reading as well as exhausting write buffer before doing sendfile;

  • replicate sendfile fallback implementation to support it for SSL transports.

Good news is that a lot of the above is already figured out in asyncio, so we just need to apply that knowledge to the slightly different IO implementation in uvloop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted missing feature a feature of vanilla asyncio is not implemented in uvloop
Projects
None yet
Development

No branches or pull requests

2 participants