3 ms·
Here's the use case that drives the design of fdclean: Imagine a third party library makes a callback to your code and hands you a file descriptor. You can use
by rumcajz 10y ago
Here's the use case that drives the design of fdclean: Imagine a third party library makes a callback to your code and hands you a file descriptor. You can use it temporarily, but you have no idea what will happen to it after you return from the callback function. Will it live on? Will it be closed? The only way to deal with that is to purge any cached info about the fd before returning and pretend that you never had anything to do with that file descriptor.
void callback(int fd) {
fdin(fd);
recv(fd, buf, len, 0);
fdclean(fd);
}