Ejemplo n.º 1
0
    def read_message(self):
        try:
            type_ = self.read_bytes(1)
            size = unpack("!I", self.read_bytes(4))[0]

            if size < 4:
                raise errors.MessageError("Bad message size: {0}".format(size))
            message = BackendMessage.factory(type_, self.read_bytes(size - 4))
            logger.debug("<= %s", message)
            return message
        except (SystemError, IOError) as e:
            self.close_socket()
            raise errors.ConnectionError(str(e))
Ejemplo n.º 2
0
    def read_message(self):
        try:
            type_ = self.read_bytes(1)
            size = unpack('!I', self.read_bytes(4))[0]

            if size < 4:
                raise errors.MessageError("Bad message size: {0}".format(size))
            message = BackendMessage.factory(type_, self.read_bytes(size - 4))
            logger.debug('<= %s', message)
            return message
        except (SystemError, IOError) as e:
            self.close_socket()
            raise errors.ConnectionError(str(e))
Ejemplo n.º 3
0
    def read_message(self):
        try:
            ready = select.select([self._socket()], [], [], self.options['read_timeout'])
            if len(ready[0]) > 0:
                type = self.read_bytes(1)
                size = unpack('!I', self.read_bytes(4))[0]

                if size < 4:
                    raise MessageError("Bad message size: {0}".format(size))
                message = BackendMessage.factory(type, self.read_bytes(size - 4))
                if getattr(self, 'debug', False):
                    print "<= {0}".format(message)
                return message
            else:
                self.close()
                raise TimedOutError("Connection timed out")
        except Exception as e:
            self.close_socket()
            raise ConnectionError(e.message)
Ejemplo n.º 4
0
    def read_message(self):
        try:
            ready = select.select([self._socket()], [], [],
                                  self.options['read_timeout'])
            if len(ready[0]) > 0:
                type = self.read_bytes(1)
                size = unpack('!I', self.read_bytes(4))[0]

                if size < 4:
                    raise errors.MessageError(
                        "Bad message size: {0}".format(size))
                message = BackendMessage.factory(type,
                                                 self.read_bytes(size - 4))
                if getattr(self, 'debug', False):
                    print "<= {0}".format(message)
                return message
            else:
                self.close()
                raise errors.TimedOutError("Connection timed out")
        except Exception as e:
            self.close_socket()
            raise errors.ConnectionError(e.message)
Ejemplo n.º 5
0
    def read_message(self):
        try:
            ready = select.select([self._socket()], [], [], self.options['read_timeout'])
            if len(ready[0]) > 0:
                type = self.read_bytes(1)
                size = unpack('!I', self.read_bytes(4))[0]

                if size < 4:
                    raise errors.MessageError(
                        "Bad message size: {0}".format(size)
                    )
                message = BackendMessage.factory(type, self.read_bytes(size - 4))
                logger.debug('<= %s', message)
                return message
            else:
                self.close()
                raise errors.TimedOutError("Connection timed out")
        except errors.TimedOutError:
            raise
        except Exception as e:
            self.close_socket()
            raise errors.ConnectionError(e.message)