def METHOD_NAME(
    host: str, port: int, will_close_then_reopen_socket: bool = False
) -> socket.socket:
    try:
        family = get_family(host=host)
        sock = socket.socket(family=family, type=socket.SOCK_STREAM)
        # Setting flags like SO_REUSEADDR and/or SO_REUSEPORT may have
        # undesirable side-effects but we allow it if caller insists. Refer to
        # comment on find_available_port()
        #
        # See e.g.  https://stackoverflow.com/a/14388707 for an extensive
        # explanation of these flags, in particular the part about TIME_WAIT
        if will_close_then_reopen_socket:
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        else:
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 0)
        sock.bind((host, port))
        return sock
    except socket.gaierror as err_info:
        raise InvalidHostException(
            f"Trying to bind socket with what looks like "
            f"an invalid hostname ({host}). "
            f"Actual "
            f"error msg is: {err_info.strerror}"
        )
    except OSError as err_info:
        if err_info.errno in (48, 98):
            raise PortAlreadyInUseException(f"Port {port} already in use.")
        raise OSError(f"Unknown `OSError` while binding port {port}") from err_info