epoll code refactor