fix bugs in poll and epoll (#1135)

* fix bugs in poll and epoll

Signed-off-by: Godones <chenlinfeng25@outlook.com>

* fix: wakeup all epitems instead of the first

Signed-off-by: Godones <chenlinfeng25@outlook.com>

* Fix wakeup_epoll error

Signed-off-by: Godones <chenlinfeng25@outlook.com>

* Make test_epoll pass

Signed-off-by: Godones <chenlinfeng25@outlook.com>

---------

Signed-off-by: Godones <chenlinfeng25@outlook.com>
This commit is contained in:
linfeng
2025-05-09 23:08:50 +08:00
committed by GitHub
parent cd3289e4b4
commit 7486ad438c
8 changed files with 62 additions and 75 deletions

View File

@ -98,19 +98,26 @@ int main() {
printf("主线程epoll_wait 返回,事件数量 = %d\n", nfds);
}
if (nfds != 2) {
printf("主线程:事件数量不匹配,预期 2实际 %d\n", nfds);
exit(EXIT_FAILURE);
}
// 由于dup复制了 eventfd 描述符,所以 只需要处理一个就行
nfds -= 1;
// 处理就绪事件
// for (int i = 0; i < nfds; i++) {
// if (events[i].data.fd == efd || events[i].data.fd == efd2) {
// uint64_t count;
// int fd = events[i].data.fd;
// printf("主线程:事件发生在 fd = %d\n", fd);
// if (read(fd, &count, sizeof(count)) != sizeof(count)) {
// perror("从 eventfd 读取失败");
// exit(EXIT_FAILURE);
// }
// printf("主线程:接收到 eventfd 事件,计数值 = %lu\n", count);
// }
// }
for (int i = 0; i < nfds; i++) {
if (events[i].data.fd == efd || events[i].data.fd == efd2) {
uint64_t count;
int fd = events[i].data.fd;
printf("主线程:事件发生在 fd = %d\n", fd);
if (read(fd, &count, sizeof(count)) != sizeof(count)) {
perror("从 eventfd 读取失败");
exit(EXIT_FAILURE);
}
printf("主线程:接收到 eventfd 事件,计数值 = %lu\n", count);
}
}
// 等待工作线程结束
pthread_join(tid, NULL);