C reading from a live file ( file keep growing in size )

╄→гoц情女王★ 提交于 2019-12-11 01:54:23

问题


I have an application that is recording live , the capture file keep growing in size using fread() and feof() , but feof() is breaking the loop early , so what's the best technique to keep reading from the stream

  • should I wait and then I can advance the file stream ?
  • should I open the file again and advance to position by calculating the total of read bytes?
  • maybe something else ?

the code will have to read the file , build a packet and send it packaging and sending is going well with fixed size files


回答1:


I would monitor the file (something like select(2)). When notified, I would read as much as possible then wait again.



来源:https://stackoverflow.com/questions/7864769/c-reading-from-a-live-file-file-keep-growing-in-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!