Пример #1
0
    def _send_packet(self, data, seq=None):
        if not self._s:
            raise Error("Attempt to run a command on a closed connection.")

        if seq is not None:
            self._seq = seq
        else:
            self._seq += 1
        packet = "%s%s%s" % (_encode_int(len(data), 3), _encode_int(self._seq), data)

        self._log.debug("Sending packet %s", hack.hexify(packet))

        if self._s.sendall(packet) is not None:
            raise InterfaceError("Send failed.")
        return len(packet)
Пример #2
0
    def _read_packet(self):
        packet_len, seq = self._get_header()

        while MYSQL_HEADER_SIZE > self._recv_length or packet_len + MYSQL_HEADER_SIZE > self._recv_length:

            self._recv()
            if packet_len is None:
                # TODO Make this less messy
                packet_len, seq = self._get_header()

        data = self._recv_buffer[MYSQL_HEADER_SIZE : MYSQL_HEADER_SIZE + packet_len]
        self._recv_buffer = self._recv_buffer[MYSQL_HEADER_SIZE + packet_len :]
        self._recv_length = self._recv_length - (MYSQL_HEADER_SIZE + packet_len)

        self._log.debug("ipkt%d:%s", seq, hack.hexify(data))

        return seq, data