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 for OS X / MacOS #560

Closed
tailhook opened this issue Mar 24, 2017 · 9 comments
Closed

Implement sendfile for OS X / MacOS #560

tailhook opened this issue Mar 24, 2017 · 9 comments

Comments

@tailhook
Copy link
Contributor

I guess this is just not implemented yet, right? Not something that's impossible or inviable to implement.

The problem might be that the system call is very different on OS X and linux. So should it be implemented on each system as is? Or should some common denominator be in nix? (given that syscall exists in libc for both platforms with different signature)

@Mic92
Copy link
Contributor

Mic92 commented Mar 25, 2017

Here is how go handle this: https://golang.org/search?q=sendfile

@kamalmarhubi
Copy link
Member

kamalmarhubi commented Apr 7, 2017

Sorry for the delayed response. I think the right way to handle this in nix is to have each platforms syscall implemented as-is, wrapping the libc implementations. Happy to accept a PR! :-)

@Susurrus Susurrus changed the title No sendfile on OS X / MacOS Implement sendfile for OS X / MacOS Jun 4, 2017
@morrowa
Copy link
Contributor

morrowa commented Apr 17, 2018

This is somewhat confusing as there is an identically named method in BSDs (including FreeBSD and Darwin) which has different semantics.

The BSD sendfile copies the contents of a file descriptor to a streaming socket whereas the Linux sendfile copies from one file descriptor to another.

What's the convention for handling this scenario? Should the BSD sendfile also be exposed under a different name?

Once this question is answered, I'd be interested in taking this ticket.

@asomers
Copy link
Member

asomers commented Apr 17, 2018

They're not as different as they sound. A streaming socket, after all, is a file descriptor. Still, there are important differences, like the sf_hdtr structure that is absent on Linux or the sbytes argument that is absent on OSX. I agree with @kamalmarhubi that it would probably be best for Nix to wrap sendfile in its native form for each operating system. Combining them all into a single cross-platform API is beyond the remit of Nix.

@morrowa
Copy link
Contributor

morrowa commented Apr 17, 2018

OK! Would wrapping the Darwin syscall implementation have any value? E.g. what Go does in their syscall package?

@asomers
Copy link
Member

asomers commented Apr 17, 2018

Oh, I don't want to get into the business of calling bare syscalls. That's caused a lot of trouble for Go. Better to use the C APIs.

@kamalmarhubi
Copy link
Member

I agree on the above. We don't have the resources to deal with the potential issues that come from bare syscalls.

I think the only time we should consider it is where the libc doesn't expose a wrapper. The cases I know of in nix are the linux calls memfd_create and pivot_root, for which glibc has no wrapper. (Well, apparently it does as of 2.27, but at two months old that's way too new.)

@morrowa
Copy link
Contributor

morrowa commented Apr 17, 2018

Sounds good. Could we modify this ticket to include both Darwin and the other BSDs, since it's the same API? I'll get started on this tonight.

@morrowa
Copy link
Contributor

morrowa commented Jan 20, 2023

This merged years ago in #901 and can be closed as complete.

@asomers asomers closed this as completed Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants