Socket refactoring: refactor socket_open