# HG changeset patch # User Shinji KONO # Date 1312515906 -32400 # Node ID 1a5afcf100a5301c5c1565026ad31bf442f62021 # Parent 7e60020f0a72c594f1c7cb4ba5c98180846d613f comments diff -r 7e60020f0a72 -r 1a5afcf100a5 src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Fri Aug 05 12:33:45 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Fri Aug 05 12:45:06 2011 +0900 @@ -640,8 +640,13 @@ // createBimgFlag = true; // rfb.addSockTmp(newCli); // addSock(newCli); + final int myId = clients; final Client > c = multicastqueue.newClient(); final AtomicBoolean writerRunning = new AtomicBoolean(); + /** + * Timeout thread. If a client is suspended, it has top of queue indefinitely, which caused memory + * overflow. After the timeout, we poll the queue and discard it. Start long wait if writer is running. + */ final Runnable timer = new Runnable() { public void run() { for(;;) { @@ -652,6 +657,7 @@ writerRunning.set(false); while (!writerRunning.get()) { c.poll(); // discard, should be timeout + System.out.println("Discarded "+myId); wait(10); // if this is too short, writer cannot take the poll, if this is too long, memory will overflow... } } @@ -661,6 +667,9 @@ } }; new Thread(timer).start(); + /** + * discard all incoming from clients + */ final Runnable reader = new Runnable() { public void run() { byte b[] = new byte[4096]; @@ -680,7 +689,9 @@ } } }; - final int myId = clients; + /** + * send packets to a client + */ Runnable sender = new Runnable() { public void run() { try { @@ -694,7 +705,7 @@ sendSecResult(os); readClientInit(is); sendInitData(os); - new Thread(reader).start(); + new Thread(reader).start(); // discard incoming packet here after. for (;;) { LinkedList bufs = c.poll(); int inputIndex = 0; @@ -704,7 +715,7 @@ System.out.println("client "+ myId); } writeToClient(os, bufs, inputIndex); - writerRunning.set(true); + writerRunning.set(true); // yes my client is awaking. } } catch (IOException e) { try {