免费注册 查看新帖 |

Chinaunix

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

嵌入式linux单板上读串口read(dev, buf,count),count居然被修改,真是奇怪呀,help [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-10-07 15:27 |只看该作者 |倒序浏览
我会多次调用这个函数read_check(dev, buf, 1或者4), 这个函数跑了大概20次左右就会出现怪事:
res1= -1, 4, 4  
res2= -1, 4, 4, 716768201  
Failed to read: Interrupted system call
read调用的count值居然被修改了!

"Failed to read:"是我在这个函数失败退出时打印的,请大家帮忙分析一下呀,搞了好几天没搞定.

这样一个函数,linux里的原代码,打印是出现问题后我打印的:
static int read_check(int fd, void *buf, int count)
{
        int res;
        int cnt=0;
       
        do {
                res = read(fd, buf, count);
                printf("res1= %d, %d, %d  \n", res, errno, EINTR);
                if (res != -1) {
                        buf += res;
                        count -= res;
                }
               printf("res2= %d, %d, %d, %d  \n", res, errno, EINTR, count);
        } while (count && (errno == 0 || errno == EINTR));  
       
        if (count)
                return -1;
       
        return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP