'Send a raw BSON message or raise ConnectionFailure.
If a network exception is raised, the socket is closed.'

def send_message(self, message, max_doc_size):

    if ((self.max_bson_size is not None) and (max_doc_size > self.max_bson_size)):
        raise DocumentTooLarge(('BSON    document    too    large    (%d    bytes)    -    the    connected    server    supports    BSON    document    sizes    up    to    %d    bytes.' % (max_doc_size, self.max_bson_size)))
    try:
        self.sock.sendall(message)
    except BaseException as error:
        self._raise_connection_failure(error)
