# HG changeset patch # User oshiro # Date 1550477314 -32400 # Node ID b9e73589202c50cfd385c93bbc8e0d18eb29234f # Parent 57ee5c26e8eb4051f06eae3866ca98314a88e2f3 fix header diff -r 57ee5c26e8eb -r b9e73589202c src/main/java/jp/ac/u_ryukyu/treevnc/CheckDelay.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/CheckDelay.java Sun Feb 17 18:39:28 2019 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/CheckDelay.java Mon Feb 18 17:08:34 2019 +0900 @@ -11,8 +11,14 @@ private ByteBuffer msg; public CheckDelay(int i, int j, int width, int height, long time, EncodingType checkDelay) { - + msg = ByteBuffer.allocate(24).order(ByteOrder.BIG_ENDIAN); + checkDelay(msg, (short) i, (short) j, (short) width, (short) height, time, checkDelay); + msg.flip(); + + } + + public static void checkDelay(ByteBuffer msg, int i, int j, int width, int height, long time, EncodingType checkDelay) { msg.put((byte) 0); // FrameBufferUpdate msg.put((byte) 0); // padding msg.putShort((short) 1); // number of rectangle @@ -22,10 +28,8 @@ msg.putShort((short) height); msg.putInt(checkDelay.getId()); msg.putLong(time); - msg.flip(); - } - + public ByteBuffer getMessage(){ return msg; } diff -r 57ee5c26e8eb -r b9e73589202c src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Sun Feb 17 18:39:28 2019 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Mon Feb 18 17:08:34 2019 +0900 @@ -30,7 +30,6 @@ public class TreeRFBProto { - final static int CheckDelay = 11; protected final static int FramebufferUpdate = 0; protected ProtocolContext context; private int clients = 0; @@ -77,6 +76,7 @@ private ByteBuffer header; private ByteBuffer c1; private FramebufferUpdateRectangle c1rect; + private int c1headerPos; public TreeRFBProto(boolean isTreeManager, ViewerInterface viewer) { nets.setMyRfb(this); @@ -761,20 +761,25 @@ this.header = header; // dump32(inputs); c1 = multicastqueue.allocate(deflate_size); + if (addSerialNum) + c1.putLong(counter++); + if (checkDelay) + CheckDelay.checkDelay(c1, rect.x, rect.y, rect.width, rect.height, System.currentTimeMillis(), EncodingType.CHECK_DELAY); + c1headerPos = c1.position(); + c1.put(header); c1rect = new FramebufferUpdateRectangle(rect.x, rect.y, 0, 0); return; } public void multicastPut(FramebufferUpdateRectangle rect, byte[] bytes, int prevoffset, int offset, int tilex, int tiley) { int span = offset - prevoffset; - int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0; deflater.setInput(bytes,prevoffset,span); c1rect.height = tiley; if (c1.remaining() < span || c1rect.x + c1rect.width + tilex >= rect.x + rect.width ) { deflater.deflate(c1, Deflater.FULL_FLUSH); c1.flip(); try { - writeUpdateRectangleWithHeader(c1,header,c1.remaining(), c1rect.x, c1rect.y, c1rect.width, c1rect.height); + writeUpdateRectangleWithHeader(c1, c1headerPos, c1.remaining(), c1rect.x, c1rect.y, c1rect.width, c1rect.height); } catch (InterruptedException e) { e.printStackTrace(); } @@ -785,36 +790,26 @@ } c1rect.width = 0; c1 = multicastqueue.allocate(deflate_size); + if (addSerialNum) + c1.putLong(counter++); + c1headerPos = c1.position(); + c1.put(header); } else { deflater.deflate(c1, Deflater.SYNC_FLUSH); } c1rect.width += tilex; } - private void writeUpdateRectangleWithHeader(ByteBuffer c1, ByteBuffer header, int len2, int x, int y, int w, int h) throws InterruptedException { - LinkedList bufs = new LinkedList(); - bufs.add(c1); + private void writeUpdateRectangleWithHeader(ByteBuffer c1, int headerPos, int len2, int x, int y, int w, int h) throws InterruptedException { deflater.reset(); - ByteBuffer blen = multicastqueue.allocate(4); - blen.putInt(len2); - blen.flip(); - bufs.addFirst(blen); - ByteBuffer hdr = multicastqueue.allocate(header.array().length); - hdr.put(header.array()); - hdr.putShort(4,(short) x); - hdr.putShort(6,(short) y); - hdr.putShort(8,(short) w); - hdr.putShort(10,(short) h); - hdr.flip(); - if (checkDelay) { - bufs = createCheckDelayHeader(bufs, hdr); - } else { - bufs.addFirst(hdr); - } - if (addSerialNum) { - addSerialNumber(bufs); - } + c1.putInt(len2); + c1.putShort(headerPos + 4,(short) x); + c1.putShort(headerPos + 6,(short) y); + c1.putShort(headerPos + 8,(short) w); + c1.putShort(headerPos + 10,(short) h); + LinkedList bufs = new LinkedList(); + bufs.add(c1); multicastqueue.waitput(bufs); }