Replace sleep with select call in stream agent