haskell / network

Low-level networking interface
http://hackage.haskell.org/package/network
Other
322 stars 186 forks source link

Sending data and file descriptors at the same time #541

Closed chris-martin closed 1 year ago

chris-martin commented 1 year ago

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 commented 1 year ago

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

chris-martin commented 1 year ago

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

kazu-yamamoto commented 1 year ago

OK. I understand.

Which do you prefer:

  1. Exporting NullSockAddr only
  2. Defining sendWithFds with NullSockAddr hidden
chris-martin commented 1 year ago

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

kazu-yamamoto commented 1 year ago

OK. Would you make a PR including the followings?

chris-martin commented 1 year ago

Sounds good, will do when I find some time.

kazu-yamamoto commented 1 year ago

@chris-martin Gentle ping.