免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2209 | 回复: 3
打印 上一主题 下一主题

help! poll() function question! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-15 18:28 |只看该作者 |倒序浏览
#include        <sys/poll.h>
#include        <unistd.h>
#include        <stdlib.h>
#include        <stdio.h>

#define BUFFSIZE 80

void err_msg(const char *p_error);

int main(void)
{
        struct pollfd        fdarray[1];
        char   buf[BUFFSIZE];       
        int    readn;       

        // initial structure member
        fdarray[0].fd      = STDIN_FILENO;
        fdarray[0].events  = POLLIN;
        fdarray[0].revents = 0;               

        if (poll(fdarray, 1, 0) == -1)
                err_msg("poll error.\n";

        if (fdarray[0].revents) { // I think question is here
                if ((readn = read(STDIN_FILENO, buf, BUFFSIZE)) < 0)
                        err_msg("read error.\n";
                if (write(STDOUT_FILENO, buf, readn) != readn)
                        err_msg("write error.\n";
        }
               
        exit(0);
}

void err_msg(const char *p_error)
{
        fprintf(stderr, p_error);
       
        exit(1);
}

====================

I want to test STDIN_FILENO desciptor, I think STDIN_FILENO descriptor is not block, but why I can't input string, program already over. where error?

please help me, sorry My system have no chinese input and my english  is very poor, sorry!


论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2006-08-15 19:48 |只看该作者
请仔细阅读poll的man pages。
里面有你的答案。

论坛徽章:
0
3 [报告]
发表于 2006-08-15 20:52 |只看该作者
thank you

论坛徽章:
0
4 [报告]
发表于 2006-08-15 21:33 |只看该作者
thank lenovo, I already find my question. thank you
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP