Skip to content

Sending data and file descriptors at the same time #541

Description

@chris-martin

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 ()

Activity

  1. kazu-yamamoto commented on Mar 20, 2023

    @kazu-yamamoto
    Collaborator

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

  2. chris-martin commented on Mar 20, 2023

    @chris-martin
    ContributorAuthor

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

  3. kazu-yamamoto commented on Mar 21, 2023

    @kazu-yamamoto
    Collaborator

    OK. I understand.

    Which do you prefer:

    1. Exporting NullSockAddr only
    2. Defining sendWithFds with NullSockAddr hidden
  4. chris-martin commented on Mar 21, 2023

    @chris-martin
    ContributorAuthor

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

  5. kazu-yamamoto commented on Mar 22, 2023

    @kazu-yamamoto
    Collaborator

    OK. Would you make a PR including the followings?

    • Implementing sendWithFds
    • Exporting NullSockAddr from Internal
  6. chris-martin commented on Mar 22, 2023

    @chris-martin
    ContributorAuthor

    Sounds good, will do when I find some time.

  7. kazu-yamamoto commented on May 17, 2023

    @kazu-yamamoto
    Collaborator

    @chris-martin Gentle ping.

  8. added a commit that references this issue on Jun 27, 2023
    12aaeec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions