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

Sending data and file descriptors at the same time #541

Closed
chris-martin opened this issue Mar 18, 2023 · 7 comments · Fixed by #562
Closed

Sending data and file descriptors at the same time #541

chris-martin opened this issue Mar 18, 2023 · 7 comments · Fixed by #562

Comments

@chris-martin
Copy link
Contributor

From my brief experimentation with Wayland, it has seemed like the Wayland server expects that when you send a message with a file descriptor parameter, it expects the message and the fd to be sent together in a single sendmsg call. The network library presently does not have any explicit support for doing this.

Currently, in my own code I have a copy of NullSocketAddress, which is internally defined in the network package but not exported.

data NullSocketAddress = NullSocketAddress

instance SocketAddress NullSocketAddress where
    sizeOfSocketAddress _ = 0
    peekSocketAddress _ = return NullSocketAddress
    pokeSocketAddress _ _ = return ()

So then I can use sendBufMsg the way the network package does internally...

Network.Socket.Address.sendBufMsg socket NullSocketAddress datas controls mempty

... where datas contains the wayland message and controls contains the file descriptor.

Proposal one (nearly no effort): It would be nice if the network library simply exported the NullSocketAddress type so that I could use it instead of duplicating it.

Proposal two (slightly more work): Some explicit support for sending data and file descriptors in a single call?

sendWithFds :: Socket -> [ByteString] -> [Fd] -> IO ()
@kazu-yamamoto
Copy link
Collaborator

I'm sorry but I don't understand this proposal a bit. Where can I find NullSocketAddress?

@chris-martin
Copy link
Contributor Author

I apologize, I forgot the words aren't completely spelled. I was attempting to refer to NullSockAddr.

@kazu-yamamoto
Copy link
Collaborator

OK. I understand.

Which do you prefer:

  1. Exporting NullSockAddr only
  2. Defining sendWithFds with NullSockAddr hidden

@chris-martin
Copy link
Contributor Author

If I could only choose one, I'd prefer the second.

@kazu-yamamoto
Copy link
Collaborator

OK. Would you make a PR including the followings?

  • Implementing sendWithFds
  • Exporting NullSockAddr from Internal

@chris-martin
Copy link
Contributor Author

Sounds good, will do when I find some time.

@kazu-yamamoto
Copy link
Collaborator

@chris-martin Gentle ping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants