Chinaunix
标题:
请问那位高手用过poll()这个函数
[打印本页]
作者:
dontknowall
时间:
2003-02-14 18:59
标题:
请问那位高手用过poll()这个函数
请问那位高手用过poll()这个函数,为什么我查不出这个函数的出处,请高人指点
作者:
cer
时间:
2003-02-14 19:22
提示:
作者被禁止或删除 内容自动屏蔽
作者:
无双
时间:
2003-02-14 22:20
标题:
请问那位高手用过poll()这个函数
写select差不多
但是可以指定对每个描述字等待的信号
以下转向ZDNET
http://www00.zdnet.com.cn:88/developer/code/story/0,2000081534,39030918,00.htm
poll()说明
poll()方法试图合并select()函数的参数,同时提供范围更广的事件通知。SUSv2 如下定义poll() 函数:
int poll(structpollfdfds[ ], nfds_tnfds, int timeout);
参数含义如下:
structpollfdfds[ ] - pollfd结构数组
nfds_tnfds - fds[ ]中文件描述符集合的数目
int timeout - poll()等待事件发生的时间长度(单位是毫秒)
返回值表示多少fds有事件发生。
pollfd结构通常包括以下结构成员:
intfd – 表示某个事件由哪个fd监视
short events – 表示哪些事件将被监视的位字段
short revents – 表示调用poll()时检测到的事件的比特位
作者:
kiss007
时间:
2003-02-17 17:10
提示:
作者被禁止或删除 内容自动屏蔽
作者:
carol1980
时间:
2003-09-10 11:51
标题:
请问那位高手用过poll()这个函数
可参考: man poll 2
我自己写的 poll 代码,用于串口设备接收input data.
#include <sys/poll.h>;
struct pollfd *ufds;
//可循环赋值多个设备,这里只有一个。
ufds ->; fd = fd; /* file descriptor */
ufds ->; events = POLLIN;
int i = poll(ufds, 1, 500); // 500 ms delay
if(i == 0) //time out
time_out++;
if(i == -1) //error occured
exit(-1);
else //data input
{
read(fd, buffer, sizeof(buffer));
...
}
更详细的可参考select 函数。
个人觉得POLL 比 SIGNAL 好,很简单。
但遇到一个问题,代码中好像必须有以下几句:
#include <sys/signal.h>;
struct sigaction saio;
若没有这两句,执行程序的时候出错:segmentation fault.
难道poll 和signal 还有什么联系吗?或者是其他原因。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2