xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #132: xpra-protocol-addlatencymeasurements2.patch

File xpra-protocol-addlatencymeasurements2.patch, 3.5 KB (added by Antoine Martin, 9 years ago)

patch for protocol.py so the latency reported is when the packet has been sent by the network layer

  • src/xpra/protocol.py

    ### Eclipse Workspace Patch 1.0
    #P Xpra
     
    155155            self._flush_one_packet_into_buffer()
    156156        return False
    157157
    158     def _queue_write(self, data, flush=False):
     158    def _queue_write(self, data, cb=None, flush=False):
    159159        """
    160160            This method should be called with _write_lock held
    161161        """
     
    163163            return
    164164        if self.raw_packets or self._compressor is None:
    165165            #raw packets are compressed individually, without the header
    166             self._write_queue.put(data)
     166            self._write_queue.put((data, cb))
    167167            return
    168168        c = self._compressor.compress(data)
    169169        if c:
    170             self._write_queue.put(c)
     170            self._write_queue.put((c, None))
    171171        if not flush:
    172172            return
    173173        c = self._compressor.flush(zlib.Z_SYNC_FLUSH)
    174174        if c:
    175             self._write_queue.put(c)
     175            self._write_queue.put((c, cb))
    176176
    177177    def verify_packet(self, packet):
    178178        """ look for None values which may have caused the packet to fail encoding """
     
    204204    def _flush_one_packet_into_buffer(self):
    205205        if not self.source:
    206206            return
    207         packet, self._source_has_more = self.source.next_packet()
     207        packet, cb, self._source_has_more = self.source.next_packet()
    208208        if packet is not None:
    209             self._add_packet_to_queue(packet)
     209            self._add_packet_to_queue(packet, cb)
    210210
    211211    def encode(self, packet):
    212212        """
     
    252252        packets.append((0, True, main_packet))
    253253        return packets
    254254
    255     def _add_packet_to_queue(self, packet):
     255    def _add_packet_to_queue(self, packet, cb=None):
    256256        packets = self.encode(packet)
    257257        if not self.raw_packets:
    258258            assert len(packets)==1
     
    276276                    header = ("PS%014d" % l).encode('latin1')
    277277                if l<4096 and sys.version<'3':
    278278                    #send size and data together (low copy overhead):
    279                     self._queue_write(header+data, True)
     279                    self._queue_write(header+data, cb, True)
    280280                else:
    281281                    self._queue_write(header)
    282                     self._queue_write(data, True)
     282                    self._queue_write(data, cb, True)
    283283        finally:
    284284            if packet[0]=="set_deflate":
    285285                level = packet[1]
     
    295295    def _write_thread_loop(self):
    296296        try:
    297297            while True:
    298                 buf = self._write_queue.get()
     298                item = self._write_queue.get()
    299299                # Used to signal that we should exit:
    300                 if buf is None:
     300                if item is None:
    301301                    log("write thread: empty marker, exiting")
    302302                    break
     303                buf, cb = item
    303304                try:
    304305                    while buf and not self._closed:
    305306                        written = untilConcludes(self._conn.write, buf)
     
    307308                            buf = buf[written:]
    308309                            self.output_raw_packetcount += 1
    309310                            self.output_bytecount += written
     311                    if cb:
     312                        cb()
    310313                except (OSError, IOError, socket.error), e:
    311314                    self._call_connection_lost("Error writing to connection: %s" % e)
    312315                    break