use poll/select to read/write with a time limit