use poll(2) on linux, select(2) on macos.