问题
Is it possible (specifically in Linux) to make a file descriptor from user-provided functions like the following?
ssize_t (*write)(int fd, const void *buf, size_t count);
ssize_t (*read)(int fd, void *buf, size_t count);
(and maybe some more functions, like close()
and/or something for polling)
It should look for the OS as a normal FD number, but be handled by the user-provided callbacks (as above) rather than by the OS itself.
The reason why I ask is to know whether it is possible to implement this feature suggestion in user-space (e.g. in Glibc) without modifying the kernel: https://bugzilla.kernel.org/show_bug.cgi?id=135401
来源:https://stackoverflow.com/questions/38467736/user-space-defined-file-descriptor-linux