/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/tests/test_smart_transport.py

  • Committer: Martin
  • Date: 2010-02-17 01:42:45 UTC
  • mto: This revision was merged to the branch mainline in revision 5117.
  • Revision ID: gzlist@googlemail.com-20100217014245-oii9iih0mvry7abk
Reintroduce EINTR handling only for socket object functions and general cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from bzrlib.transport.http import SmartClientHTTPMediumRequest
50
50
 
51
51
 
 
52
def _recv_all(socket, bytes):
 
53
    """Receive an exact number of bytes.
 
54
 
 
55
    Regular Socket.recv() may return less than the requested number of bytes,
 
56
    depending on what's in the OS buffer.  MSG_WAITALL is not available
 
57
    on all platforms, but this should work everywhere.  This will return
 
58
    less than the requested amount if the remote end closes.
 
59
 
 
60
    This isn't optimized and is intended mostly for use in testing. Should be
 
61
    replaced with a more appropriate interface.
 
62
    """
 
63
    b = ''
 
64
    reporter = lambda n, rw: None
 
65
    while len(b) < bytes:
 
66
        new = medium._read_bytes_from_socket(socket, bytes - len(b), reporter)
 
67
        if new == '':
 
68
            break # eof
 
69
        b += new
 
70
    return b
 
71
 
 
72
 
52
73
class StringIOSSHVendor(object):
53
74
    """A SSH vendor that uses StringIO to buffer writes and answer reads."""
54
75
 
127
148
        """
128
149
        def _receive_bytes_on_server():
129
150
            connection, address = sock.accept()
130
 
            bytes.append(osutils.recv_all(connection, 3))
 
151
            bytes.append(_recv_all(connection, 3))
131
152
            connection.close()
132
153
        t = threading.Thread(target=_receive_bytes_on_server)
133
154
        t.start()
734
755
        client_sock.sendall(rest_of_request_bytes)
735
756
        server._serve_one_request(server_protocol)
736
757
        server_sock.close()
737
 
        self.assertEqual(expected_response, osutils.recv_all(client_sock, 50),
 
758
        self.assertEqual(expected_response, _recv_all(client_sock, 50),
738
759
                         "Not a version 2 response to 'hello' request.")
739
760
        self.assertEqual('', client_sock.recv(1))
740
761