Socket refactoring: refactor free port lookup