- 论坛徽章:
- 0
|
ldd 第165页的 poll 函数,代码如下- 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;
- }
复制代码 把这个poll函数用在scullpipe上。然后写个程序来测试这个poll函数,代码如下- #include<poll.h>
- #include<stdio.h>
- #include<fcntl.h>
- #include<unistd.h>
- int main()
- {
- int ret;
- int fd = open("/dev/scullp",O_RDONLY);
- struct pollfd fdarray[1];
- fdarray[0].fd = 1;
- fdarray[0].events = POLLIN | POLLRDNORM;
- ret = poll(fdarray,1,2000);
- printf("ret is %d,%d,%d\n",ret,fdarray[0].events,fdarray[0].revents);
- return 0;
- }
复制代码 奇怪的是,这个程序会卡在那里,用Ctrl+c也没办法终止,用printk来调试,发现程序卡在poll函数里面的的poll_wait函数上了,照理说我设定了时间为2秒,2秒不是应该会返回吗,请问各位这是什么原因呢
|
|