The most common processing method IO::EAGAINWaitReadable:
begin
result = io.read_nonblock(maxlen)
rescue IO::EAGAINWaitReadable
IO.select([io])
retry
end
So you can do this without choosing a port, but better with a choice, as shown in the example. You can also see the SO answer on how to catch in WaitReadableaddition to the specified.