Use IO.select for detecting socket connection timeout