2 ms·
A convenient fact is that file descriptors are just numbers, and the lowest available number is always used when creating a new socket, so it's naturally easy
by akira2501 3y ago
A convenient fact is that file descriptors are just numbers, and the lowest available number is always used when creating a new socket, so it's naturally easy to just keep all your structures in a giant array and use the fd into index into it to retrieve the structure that represents the connection.
From there it's just choosing a function to dispatch to based upon epoll event and being exceptionally careful to always use non blocking IO on the underlying fd.