From 9bed42bfcdb548c2f097a7536d3fa6a4117b57e9 Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Thu, 1 Dec 2022 23:40:27 +0800 Subject: Save sockets inside epoll data --- eventloop.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'eventloop.c') diff --git a/eventloop.c b/eventloop.c index f79114d..9a26b98 100644 --- a/eventloop.c +++ b/eventloop.c @@ -19,10 +19,7 @@ int eventLoopAddSocket(struct eventLoop *el, struct tsocket *sock, int flag) { struct epoll_event ev; ev.events = flag; - ev.data.fd = sock->fd; - - // TODO: How the fd ranges? Will it be larger than the MAX_EVENTS? - el->socks[sock->fd] = sock; + ev.data.ptr = sock; return epoll_ctl(el->epollfd, EPOLL_CTL_ADD, sock->fd, &ev); } @@ -34,6 +31,5 @@ int eventLoopWait(struct eventLoop *el, int timeout) struct tsocket *eventLoopGetSocket(struct eventLoop *el, int index) { - int fd = el->events[index].data.fd; - return el->socks[fd]; + return (struct tsocket *)el->events[index].data.ptr; } -- cgit v1.2.3