I started writing a Wayland client using SwiftNIO, Mostly following this blog post with the plan of branching out out to ray tracing in one weekend and trying out InlineArray after I get the red square working.
It's been going prettty well but to share memory with Wayland they ask you to send of the file descriptor using sendmsg, cmsghdr . I see referenses to them in SwiftNIO but nothing public. I was wondering if anyone knew how to work around this with SwiftNIO?
This is a cool project Zane, let's see if we can help you bring it to fruition!
Today, NIO never uses sendmsg to issue writes on TCP channels. We do use it for UDP channels, though, which is why you have seen the bindings.
To enable this use-case, then, we need a way for you to optionally "extend" a channel created from a ClientBootstrap (and the child channels from ServerBootstrap) to opt-in to sending objects with metadata.
Achieving this requires several moving pieces, I think:
Defining a new type to represent this "data + control data" object. This would look similar to AddressedEnvelope, but is actually just a struct containing a ByteBuffer and a Metadata type like the AddressedEnvelope metadata. We could even choose to entirely re-use it.
A substantial change to PendingStreamWritesManager that allows the use of sendmsg/recvmsg when using this alternative data-type.
Defining a new ChannelOption that can be used to request a change on the input and output datatypes from the channel. When set, this should flip our I/O functions from read/write/writev to recvmsg/sendmmsg.
As I'm sure you can see, this isn't totally trivial to achieve, but if you're motivated to do it I can help walk you through the various steps.