Ability to adopt file descriptors
This patch adds support for adopting an existing file descriptor, together
with testcases. The need for this comes up when we use systemd with the
ListenMessageQueue directive. For socket activation, systemd opens the POSIX
message queue and expects user code to begin using the file descriptor
without opening it in-process.
To support the systemd model in the `posix_mq` gem, this patch suggests
imitating the behavior on the Socket class, which uses `#for_fd` to create a
socket class from a descriptor.
One confounding factor exists. POSIX queues have a name but it is difficult
to get access to this name in a safe manner from the file descriptor. One
option would be to `readlink(2)` on `/proc/self/fd/N` to get the name[1], but
note that if the descriptor is unlinked we wouldn't get anything usable.
Rather than risk incorrect behavior and extra complexity, I've decided to
just raise an `ArgumentError` if `#name` is called on adopted descriptors.
Typically one wouldn't need the actual name in a systemd socket-activated
situation, anyway.
[1]: http://stackoverflow.com/questions/
1188757/getting-filename-from-file-descriptor-in-c
[ew: simplified type checks to be consistent with IO.for_fd,
fixed test case]
Signed-off-by: Eric Wong <normalperson@yhbt.net>