IO模型

1、五种IO模型

      

 

2、select

int select(int maxfdp1, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict exeptfds, struct timeval *restrict timeout);
        成功返回就绪fd数目,超时返回0,出错返回-1

  几个宏:FD_ISSET  FD_CLR  FD_SET  FD_ZERO

  eg. unpv1  141页

 

3、poll函数    POLLINNORM  POLLWRNORM  POLLERR

int poll(struct pollfd *fdarray, unsigned long nfds, int timeout);
        返回就绪数目,超时0,出错-1
    struct pollfd{
        int fd;
        short events;
        short revents;
    }

    eg. unpv1  147页

 

4、epoll

  LT水平触发,ET边缘出发

  epoll优点:  1、支持一个进程打开大数目的socket描述符

           2、IO效率不随FD数目增加而线性下降,只对活跃的IO事件操作

           3、内核微调,epoll是通过内核与用户空间mmap同一块内存实现的

posted @ 2016-03-06 14:56  zhou09  阅读(155)  评论(0编辑  收藏  举报