'Receive a message (or more than one) from RPC'

def rx(self, msg, seq):

    good = True
    def do_rx(msg):
        if isinstance(msg, list):
            for m in msg:
                self._rx_message(m)
        else:
            self._rx_message(msg)
    if (self._rx_seq is None):
        self._rx_seq = seq
    if (seq is None):
        do_rx(msg)
    elif (seq == self._rx_seq):
        self._rx_seq += 1
        do_rx(msg)
        if (len(self._rx_buffer) > 0):
            self._rx_buffer.sort()
            if (self._rx_buffer[0][0] != self._rx_seq):
                log.info('Still    out    of    order')
                good = False
            else:
                log.info('Resuming    rx')
                while (self._rx_buffer[0][0] == self._rx_seq):
                    m = self._rx_buffer.pop(0)
                    self._rx_seq += 1
                    do_rx(msg)
                if (len(self._rx_buffer) > 0):
                    log.info('Re-suspending    rx')
                    good = False
    else:
        good = False
        self._rx_buffer.append((seq, msg))
        if (len(self._rx_buffer) == 1):
            log.info('Got    out    of    order    message    --    suspending    rx')
    return _result({'ok': good, 'ack': self._rx_seq})
