代码改变世界

Using fscanf to read message from FIFO will lost message

2016-04-23 16:52  flyfish163  阅读(312)  评论(0编辑  收藏  举报

In libcurl example hiperfifo.c, function fifo_cb uses fscanf(fifo inputstream,...) to read in a string.
rv=fscanf(g->input, "%1023s%n", s, &n);
When the fifo content producer sends two urls continuously with no interval, the fifo_cb will lost the second url.
But if the fifo content producer sends the second url 3ms later, the fifo_cb will not lost it.
With using read (fd,...) instead of fscanf,
read_res = read(fd, &dwMsgPtr, sizeof(dwMsgPtr));
the fifo_cb will not lost the second url even if the fifo content producer sends two urls continuously with no interval.