'Handles new client requests readable from \'read\'.'

def HandleClient(self, sock, permissions):

    sock.settimeout(self.CLIENT_TIMEOUT_TIME)
    cmdlen_str = self._ReadExactlyFailAfterFirst(sock, sutils.SIZE_PACKER.size)
    if (not cmdlen_str):
        return ''
    cmdlen = sutils.SIZE_PACKER.unpack(cmdlen_str)[0]
    sock.settimeout(self.READ_TIMEOUT)
    try:
        cmd_str = self._ReadExactly(sock, cmdlen)
    except (socket.timeout, socket.error):
        return ''
    cmd = rdf_data_server.DataStoreCommand.FromSerializedString(cmd_str)
    request = cmd.request
    op = cmd.command
    cmdinfo = self.CMDTABLE.get(op)
    if (not cmdinfo):
        logging.error('Unrecognized    command    %d', op)
        return ''
    (method, perm) = cmdinfo
    if (perm in permissions):
        response = method(request)
    else:
        status_desc = ('Operation    not    allowed:    required    %s    but    only    have    %s    permissions' % (perm, permissions))
        resp = rdf_data_store.DataStoreResponse(request=cmd.request, status_desc=status_desc, status=rdf_data_store.DataStoreResponse.Status.AUTHORIZATION_DENIED)
        response = resp.SerializeToString()
    return (sutils.SIZE_PACKER.pack(len(response)) + response)
