摘要: epollepoll是一种高效的管理socket的模型,相对于select和poll来说具有更高的效率和易用性。传统的select以及poll的效率会随socket数量的线形递增而呈二次乃至三次方的下降,而epoll的性能不会随socket数量增加而下降。标准的linux-2.4.20内核不支持epoll,需要打patch。本文主要从linux-2.4.32和linux-2.6.10两个内核版本介绍epoll。1. 头文件#include <sys/epoll.h>2. 参数说明int epoll_create(int size);int epoll_ctl(int epfd, i 阅读全文
posted @ 2013-04-01 17:18 alyssa.cui 阅读(1192) 评论(0) 推荐(0) 编辑
摘要: pollpoll或select为大部分Unix/Linux程序员所熟悉,这俩个东西原理类似,性能上也不存在明显差异,但select对所监控的文件描述符数量有限制,所以这里选用poll做说明。1. 头文件# include < sys/ poll. h>2. 参数说明int poll ( struct pollfd * fds, unsigned int nfds, int timeout);和select()不一样,poll()没有使用低效的三个基于位的文件描述符set,而是采用了一个单独的结构体pollfd数组,由fds指针指向这个组。pollfd结构体定义如下:struct p 阅读全文
posted @ 2013-04-01 17:12 alyssa.cui 阅读(12249) 评论(0) 推荐(0) 编辑
摘要: select1. 头文件#include<sys/time.h>#include<sys/types.h>#include<unistd.h>2. 参数说明int select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout);先说明两个结构体:第一,struct fd_set可以理解为一个集合,这个集合中存放的是文件描述符(filedescriptor),即文件句柄,这可以是我们所说的普通意义的文件,当然Unix下任何设备、管道、FIF 阅读全文
posted @ 2013-04-01 17:02 alyssa.cui 阅读(867) 评论(0) 推荐(0) 编辑