~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/smart.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-16 00:28:09 UTC
  • mto: This revision was merged to the branch mainline in revision 2020.
  • Revision ID: john@arbash-meinel.com-20060916002809-3b60a139b214b6fa
Implement readv() for the SmartServer

Show diffs side-by-side

added added

removed removed

Lines of Context:
369
369
                self._recv_body(),
370
370
                self._deserialise_optional_mode(mode))
371
371
 
 
372
    @staticmethod
 
373
    def _deserialise_offsets(text):
 
374
        offsets = []
 
375
        for line in text.split('\n'):
 
376
            if not line:
 
377
                continue
 
378
            start, length = line.split(',')
 
379
            offsets.append((int(start), int(length)))
 
380
        return offsets
 
381
 
 
382
    def do_readv(self, relpath):
 
383
        offsets = self._deserialise_offsets(self._recv_body())
 
384
        backing_bytes = ''.join(bytes for offset, bytes in
 
385
                             self._backing_transport.readv(relpath, offsets))
 
386
        return SmartServerResponse(('readv',), backing_bytes)
 
387
        
372
388
    def do_rename(self, rel_from, rel_to):
373
389
        self._backing_transport.rename(rel_from, rel_to)
374
390
 
689
705
        resp = self._client._call('delete', self._remote_path(relpath))
690
706
        self._translate_error(resp)
691
707
 
 
708
    @staticmethod
 
709
    def _serialise_offsets(offsets):
 
710
        txt = []
 
711
        for start, length in offsets:
 
712
            txt.append('%d,%d' % (start, length))
 
713
        return '\n'.join(txt)
 
714
 
 
715
    def readv(self, relpath, offsets):
 
716
        if not offsets:
 
717
            return
 
718
 
 
719
        offsets = list(offsets)
 
720
        resp = self._client._call_with_upload(
 
721
            'readv',
 
722
            (self._remote_path(relpath),),
 
723
            self._serialise_offsets(offsets))
 
724
 
 
725
        if resp[0] != 'readv':
 
726
            self._translate_error(resp)
 
727
        else:
 
728
            data = self._client._recv_bulk()
 
729
            cur_pos = 0
 
730
            for start, length in offsets:
 
731
                next_pos = cur_pos + length
 
732
                if len(data) < next_pos:
 
733
                    pass # XXX: ShortReadv, raise an error once that is merged
 
734
                cur_data = data[cur_pos:next_pos]
 
735
                cur_pos = next_pos
 
736
                yield start, cur_data
 
737
 
692
738
    def rename(self, rel_from, rel_to):
693
739
        self._call('rename', 
694
740
                   self._remote_path(rel_from),