开发者

how to filter/send messages as they arrive

I want to write a c program that keeps reading a file and whenever a new line is added to that file, its sent across network (lets assume via tcp) to recipient.

What is the best way to do it?

o keep the file open and do something like tail -F on it to keep reading?

o read file on my own?

I am 开发者_Python百科not worried about sending on network part, I need to have best way of getting a new line out of the file. On that line I might do some filtering too before sending.


Linux has inotify, OS X has kqueue/kevent, Windows has similar stuff. All of these let your process block until the kernel notifies you of a change to the file. This is very efficient because your process can sleep until a change actually happens, but obviously these interfaces are not portable.

The only portable approach is to poll the file periodically to see if it changes, but obviously that is not as efficient.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜