I love this article. It’s amazing how so many different features of Unix from the 80s are just now being rediscovered and put to new uses today.
This is becoming so important that there really should be a new API for it that isn’t so filled with traps and pitfalls.
DuplicateHandle is just the better design.
Windows basically always has the better designs. I’m so jealous.
But yeah, I use both these in an experimental web server that transfers connections to other specialized servers, like a websocket might go to the separate websocket server for more efficiency than the main one can provide.
Worth noting though that transferring a fd is actually kinda slow and you do need to use care to ensure you don’t misuse a duplicate. It is one of those things that you should probably only do if you must, not just because you can.
There are other subtleties, e.g. if you only want to transfer a descriptor and not a message with it - some implementations will happily just forward an empty message, while others (hi OSX..) will just drop it in transit; that was some debugging fun.
On the graphics side it is being overused now that not only are everyone flinging descriptors around, but they can be fragmented with one logical ‘window’ having multiple image planes. In the dma-buf model they are not aggregated together into one abstract handle, but rather sent as individual descriptors.
What happens when receiver_ulimit % n_planes in a transfer and you run out of descriptor table space? Chaos. In Wayland this is exaggerated as client-side decorations force some with mixed contents (movie players and the likes) to segment into subsurfaces, and you can easily end up with (surface,subsurfaces) that gnaw up 40+ entries alone for one logical double-buffered window.
systemd supports handling opened sockets between restarts in similar manner as well, OotB.
I had no idea this was possible. It seems similar to the way Darwin (well, Mach) allows a Mach port to be transferred over a Mach message. I’ve never done it directly, but I understand it’s a key part of how IPC works in Darwin.