changeset 112:1a5afcf100a5

comments
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 05 Aug 2011 12:45:06 +0900
parents 7e60020f0a72
children 8424f64dd736
files src/myVncProxy/MyRfbProto.java
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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 <LinkedList<ByteBuffer>> 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<ByteBuffer> 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 {