Chinaunix

标题: 嵌入式linux单板上读串口read(dev, buf,count),count居然被修改,真是奇怪呀,help [打印本页]

作者: netbuggao    时间: 2006-10-07 15:27
标题: 嵌入式linux单板上读串口read(dev, buf,count),count居然被修改,真是奇怪呀,help
我会多次调用这个函数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;
}




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