Refactoring of socket multiplexing