No. If this were possible, it would have to be tracked by the kernel, and therefore the search for this data would require a system call. The cost of a system call is an order of magnitude more expensive than finding O (n) in user space.
How many clients do you deal at once? If it does not cost hundreds or more, the cost of the search will be minimal compared to the cost of any I / O.
Instead of using O (n) search, you can also just use an array indexed by a file descriptor, provided that you cannot open several specific descriptors at once. For instance:
#define MY_MAX_FD 1024
void *per_fd_data[MY_MAX_FD];
void *get_per_fd_data(int fd)
{
assert(fd >= 0);
if(fd < MY_MAX_FD)
return per_fd_data[fd];
else
{
}
}
source
share