/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Andrew Bennetts
  • Date: 2010-06-16 07:45:53 UTC
  • mto: This revision was merged to the branch mainline in revision 5299.
  • Revision ID: andrew.bennetts@canonical.com-20100616074553-d1z8ibry8lq759w2
Tweaks prompted by Robert's review.

Show diffs side-by-side

added added

removed removed

Lines of Context:
792
792
    def _accept_bytes(self, bytes):
793
793
        """See SmartClientStreamMedium.accept_bytes."""
794
794
        self._ensure_connection()
795
 
        # XXX: Perhaps should use accept_bytes rather than _accept_bytes?
796
 
        self._real_medium._accept_bytes(bytes)
 
795
        self._real_medium.accept_bytes(bytes)
797
796
 
798
797
    def disconnect(self):
799
798
        """See SmartClientMedium.disconnect()."""
838
837
        """See SmartClientStreamMedium.read_bytes."""
839
838
        if self._real_medium is None:
840
839
            raise errors.MediumNotConnected(self)
841
 
        # XXX: perhaps should delegate to read_bytes, not _read_bytes?
842
 
        return self._real_medium._read_bytes(count)
 
840
        return self._real_medium.read_bytes(count)
843
841
 
844
842
 
845
843
# Port 4155 is the default port for bzr://, registered with IANA.
848
846
 
849
847
 
850
848
class SmartClientSocketMedium(SmartClientStreamMedium):
851
 
    """A client medium using sockets."""
 
849
    """A client medium using a socket.
 
850
    
 
851
    This class isn't usable directly.  Use one of its subclasses instead.
 
852
    """
852
853
 
853
854
    def __init__(self, base):
854
 
        """Creates a client that will connect on the first use."""
855
855
        SmartClientStreamMedium.__init__(self, base)
856
856
        self._socket = None
857
857
        self._connected = False
861
861
        self._ensure_connection()
862
862
        osutils.send_all(self._socket, bytes, self._report_activity)
863
863
 
 
864
    def _ensure_connection(self):
 
865
        """Connect this medium if not already connected."""
 
866
        raise NotImplementedError(self._ensure_connection)
 
867
 
864
868
    def _flush(self):
865
869
        """See SmartClientStreamMedium._flush().
866
870
 
867
 
        For TCP we do no flushing. We may want to turn off TCP_NODELAY and
868
 
        add a means to do a flush, but that can be done in the future.
 
871
        For sockets we do no flushing. For TCP sockets we may want to turn off
 
872
        TCP_NODELAY and add a means to do a flush, but that can be done in the
 
873
        future.
869
874
        """
870
875
 
871
876
    def _read_bytes(self, count):
885
890
 
886
891
 
887
892
class SmartTCPClientMedium(SmartClientSocketMedium):
888
 
    """A client medium using TCP."""
 
893
    """A client medium that creates a TCP connection."""
889
894
 
890
895
    def __init__(self, host, port, base):
891
896
        """Creates a client that will connect on the first use."""
892
897
        SmartClientSocketMedium.__init__(self, base)
893
 
        self._connected = False
894
898
        self._host = host
895
899
        self._port = port
896
 
        self._socket = None
897
900
 
898
901
    def _ensure_connection(self):
899
902
        """Connect this medium if not already connected."""