Chinaunix

标题: poll操作时的疑问 [打印本页]

作者: tristin    时间: 2005-12-14 11:30
标题: poll操作时的疑问
我在开发一个proxy的时候碰到了一个奇怪的问题:
proxy的监听端口上执行poll时总是返回errno=EINTR,但是用ethereal在本机抓包可以看到这个端口上已经收到了对方发的包,poll中的fd对应的socket也已经绑定正确的端口。
大侠们能不能给点思路,可能是什么原因导致收到包时poll无效?
作者: wolf0403    时间: 2005-12-14 17:45
系统调用被信号打断才会返回 EINTR 的
作者: tristin    时间: 2005-12-15 17:26
那能不能查看是什么样的系统调用呢?
我在poll里面设置的timeout是-1
作者: wolf0403    时间: 2005-12-16 00:38
poll 就是这个被打断的系统调用了。如果 poll 返回 -1 且这时 errno == EINTR,那么就是说明 poll 的过程被一个信号打断。

贴出你相关的代码片断看看吧。
作者: tristin    时间: 2005-12-16 09:19
while(1) {
        if (rtp_nsessions > 0)
            timeout = RTPS_TICKS_MIN;
        else
            timeout = INFTIM;
        sigprocmask(SIG_UNBLOCK, &set, &oset);
        i = poll(fds, nsessions + 1, timeout);
        if (i < 0 && errno == EINTR)
            continue;
                sigprocmask(SIG_BLOCK, &set, &oset);
...

RTPS_TICKS_MIN=10
INFTIM=-1
nsessions=1
即使有收到报文时也执行了continue




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2