I am trying to write a system log parser. It will receive messages from the FreeBsd syslog daemon through stdin.
It will use those messages to determine if an ip should be banned or not. The problem I have is that after x seconds the ban should be removed, but if I won't get any input from stdin, my program will just block waiting for it. So in the mean time I can't do anything.
I fixed it using threads, but isn't there a better way to do it?
For example something like this:
while true:
while <data in stdin>:
handleData
doSomeStuff()
So as long nothing comes in from stdin I want to execute doSomeStuff, and if there is data handle it.