重读2.4 052 fs/select.c target="_blank">http://docs.google.com/Doc?id=dcbsxfpf_213vc73kssk 2008-4-22 这里讨论的是select和poll的系统调用实现方式. 首先要熟悉的是内核中为poll和select定义的各种输入输出消息的含义: pollIN 有数据可以读入,read不会阻塞,注意:select的请情况下,即使到EOF也是ready的. pollPRI 紧急数据,比如TCP,或者packet 模式的peseudo-terminal发现slave的状态有变化....
在linux下select函数的最大可管理的socket连接数是FD_SETSIZE=1024,在网上看见说使用poll的话可以突破1024的限制,但是我在把程序由select改为poll以后连接数到了1024以后,仍然不能建立连接,还是有1024这个限制,不知道poll是不是还是跟select一样,受到linux内核的限制?
while(1) { iRet = poll(&sapoll, 1, 1000); if(iRet==-1) { error; } else if (iret==0) { poll timeout; } if( sapoll.revents & pollIN ) { 接收数据 } } 为何程序运行后日志总是出现poll timeout。而收不到任何数据呢? 这是因为超时,但是sapoll还没准备好吗?
下记以外的其他网址上的关联内容: http://www.builder.com.cn/2002/0320/45489.shtml Chapter 2. 一般文件操作(包括管道和套接字)Table of Contents2.1. 如何管理多个连接? 2.2. 我如何才能知道和对方的连接被终止? 2.3. 什么是读取目录的最好方法? 2.4. 我如何才能知道一个文件被另外进程打开? 2.5. 我如何锁住一个文件? 2.6. 我如何能发现一个文件已由另外一个进程更新? 2.7. 请问du是怎样工作的? 2.8. 我...
ldd 第165页的 poll 函数,代码如下[code]unsigned int scullp_poll(struct file *filp,poll_table *wait) { unsigned int mask = 0; down(&scullp->sem); poll_wait(filp,&scullp->inq,wait); poll_wait(filp,&scullp->outq,wait); if(scullp->rp != scullp->wp) mask |= pollIN | pollRDNORM; if(spacefree()) mask |= pollOUT | pollWRNORM; up(&scullp->sem); return mask; }[/code]把这个p...
本帖最后由 lanlovehua 于 2010-09-27 15:59 编辑 [code]typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *); typedef struct poll_table_struct { poll_queue_proc qproc; } poll_table; static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p) { if (p && wait_address) p->qproc(filp, wait_ad...
linux设备驱动程序第三版有如下代码: static unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal. */ down(&dev->sem); ...