def write(self, message, vsocket=None):
    if (not isinstance(message, FrontendMessage)):
        raise TypeError('invalid message: ({0})'.format(message))
    if (vsocket is None):
        vsocket = self._socket()
    self._logger.debug('=> %s', message)
    try:
        for data in message.fetch_message():
            size = 8192
            pos = 0
            while (pos < len(data)):
                sent = vsocket.send(data[pos:(pos + size)])
                if (sent == 0):
                    raise errors.ConnectionError("Couldn't send message: Socket connection broken")
                pos += sent
    except Exception as e:
        self.close_socket()
        self._logger.error(str(e))
        if isinstance(e, IOError):
            raise_from(errors.ConnectionError(str(e)), e)
        else:
            raise
def write(self, message, vsocket=None):
    if (not isinstance(message, FrontendMessage)):
        raise TypeError('invalid message: ({0})'.format(message))
    if (vsocket is None):
        vsocket = self._socket()
    self._logger.debug('=> %s', message)
    try:
        for data in message.fetch_message():
            size = 8192
            pos = 0
            while (pos < len(data)):
                sent = vsocket.send(data[pos:(pos + size)])
                if (sent == 0):
                    raise errors.ConnectionError("Couldn't send message: Socket connection broken")
                pos += sent
    except Exception as e:
        self.close_socket()
        self._logger.error(str(e))
        if isinstance(e, IOError):
            raise_from(errors.ConnectionError(str(e)), e)
        else:
            raise