Linux 多路复用 I/O 与内核 I/O 实现详解
在 Linux 系统中,高效的 I/O 操作至关重要。为了实现多路复用 I/O,Linux 提供了三种解决方案: select 、 poll 和 epoll 接口。本文将详细介绍 select 和 poll 接口,并深入探讨 Linux 内核的 I/O 实现机制。
1. select( ) 系统调用
select( ) 系统调用提供了一种实现同步多路复用 I/O 的机制。其原型如下:
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int select (int n,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
struct timeval *timeout);
同时,还提供了几个辅助宏:
FD_CLR(int fd, fd_set *set);
FD_ISSET(int fd, fd_set *set);
FD_SET(int fd, fd_set *set);
FD_ZERO(fd_set *set);
超级会员免费看
订阅专栏 解锁全文
1208

被折叠的 条评论
为什么被折叠?



