mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 13:16:31 +00:00
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:
@ -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);
|
||||
|
Reference in New Issue
Block a user