def transmit(self, frame):
        """
        Convert a frame object to a frame string and transmit to the server.
        """
        for listener in self.listeners.values():
            if not listener: continue
            if not hasattr(listener, 'on_send'):
                continue
            listener.on_send(frame)

        lines = utils.convert_frame_to_lines(frame)

        packed_frame = pack(lines)

        log.info("Sending frame %s", lines)

        if self.socket is not None:
            try:
                self.__socket_semaphore.acquire()
                try:
                    self.send_over_socket(encode(packed_frame))
                finally:
                    self.__socket_semaphore.release()
            except Exception:
                _, e, _ = sys.exc_info()
                log.error("Error sending frame", exc_info=1)
                raise e
        else:
            raise exception.NotConnectedException()
Example #2
0
    def transmit(self, frame):
        """
        Convert a frame object to a frame string and transmit to the server.
        """
        for listener in self.listeners.values():
            if not listener: continue
            if not hasattr(listener, 'on_send'):
                continue
            listener.on_send(frame)

        lines = utils.convert_frame_to_lines(frame)

        packed_frame = pack(lines)

        log.info("Sending frame %s", lines)

        if self.socket is not None:
            try:
                self.__socket_semaphore.acquire()
                try:
                    self.send_over_socket(encode(packed_frame))
                finally:
                    self.__socket_semaphore.release()
            except Exception:
                _, e, _ = sys.exc_info()
                log.error("Error sending frame", exc_info=1)
                raise e
        else:
            raise exception.NotConnectedException()
Example #3
0
    def send_frame(self, frame):
        """
        Convert a frame object to a frame string and transmit to the server.
        """
        for listener in self.listeners.values():
            if not listener: continue
            if not hasattr(listener, 'on_send'):
                continue
            listener.on_send(frame)

        lines = [ ]
        if frame.cmd:
            lines.append(frame.cmd)
            lines.append("\n")
        for key, vals in sorted(frame.headers.items()):
            if type(vals) != tuple:
                vals = ( vals, )
            for val in vals:
                lines.append('%s:%s\n' % (key, val))
        lines.append('\n')
        if frame.body:
            lines.append(frame.body)

        if frame.cmd:
            lines.append(NULL)

        packed_frame = pack(lines)

        log.info("Sending frame %s" % lines)

        if self.__socket is not None:
            try:
                self.__socket_semaphore.acquire()
                try:
                    self.__socket.sendall(encode(packed_frame))
                finally:
                    self.__socket_semaphore.release()
            except Exception:
                _, e, _ = sys.exc_info()
                log.error("Error sending frame: %s" % e)
                raise e
        else:
            raise exception.NotConnectedException()