changeset 102:1f7ee648e1f6

inflator in MyRfbProtoProxy should be renew to accept new VNC server socket. old receiver / sender task are stopped in server change
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 23 May 2014 01:45:06 +0900
parents 34ced177381b
children 84f254d8bde4
files src/main/java/com/glavsoft/rfb/protocol/Protocol.java src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java
diffstat 5 files changed, 46 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java	Thu May 22 22:03:14 2014 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java	Fri May 23 01:45:06 2014 +0900
@@ -278,13 +278,13 @@
 	@Override
 	public void cleanUpSession(String message) {
 		cleanUpSession();
-		rfbSessionListener.rfbSessionStopped(message);
+		if (message!=null)
+		    rfbSessionListener.rfbSessionStopped(message);
 	}
 
 	public synchronized void cleanUpSession() {
-		if (senderTask != null) { senderTask.stopTask(); }
-		if (receiverTask != null) { receiverTask.stopTask(); }
 		if (senderTask != null) {
+		    senderTask.stopTask(); 
 			try {
 				senderThread.join(1000);
 			} catch (InterruptedException e) {
@@ -292,15 +292,21 @@
 			}
 			senderTask = null;
 		}
-		if (receiverTask != null) {
+		stopReceiverTask();
+	}
+
+	@Override
+    public void stopReceiverTask() {
+        if (receiverTask != null) {
+		    receiverTask.stopTask(); 
 			try {
-				receiverThread.join(1000);
+				receiverThread.join();
 			} catch (InterruptedException e) {
 				// nop
 			}
 			receiverTask = null;
 		}
-	}
+    }
 
     @Override
     public void setTight(boolean isTight) {
@@ -342,14 +348,14 @@
 		settings.addListener(repaintController);
 		sendRefreshMessage();
 		senderTask = new SenderTask(messageQueue, writer, this);
-		senderThread = new Thread(senderTask);
+		senderThread = new Thread(senderTask,"sender-task");
 		senderThread.start();
 		decoders.resetDecoders();
 		receiverTask = new TreeTask(
 				reader, repaintController,
 				clipboardController,
 				decoders, this, rfb);
-		receiverThread = new Thread(receiverTask);
+		receiverThread = new Thread(receiverTask,"receiver-task");
 		receiverThread.start();
 	}
 
@@ -418,4 +424,9 @@
 		receiverThread = new Thread(receiverTask, "TreeTask");
 		receiverThread.start();
 	}
+
+    @Override
+    public void resetDecoder() {
+        decoders.resetDecoders();
+    }
 }
--- a/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java	Thu May 22 22:03:14 2014 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java	Fri May 23 01:45:06 2014 +0900
@@ -72,5 +72,9 @@
     String getProtocolVersion();
 
 	void setInitData(byte[] initData);
+
+    void resetDecoder();
+
+    void stopReceiverTask();
 	
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Thu May 22 22:03:14 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Fri May 23 01:45:06 2014 +0900
@@ -374,7 +374,7 @@
 
 
 	public void close() {
-		//nothing
+	    // none
 	}
 	
 	public int getAcceptPort() {
@@ -432,5 +432,15 @@
 		serialNum.flip();
 		bufs.addFirst(serialNum);
 	}
+
+
+    public void resetDecoder() {
+        context.resetDecoder();
+    }
+
+    public void stopReceiverTask() {
+        if (context!=null)
+            context.cleanUpSession(null);
+    }
 	
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java	Thu May 22 22:03:14 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java	Fri May 23 01:45:06 2014 +0900
@@ -567,5 +567,11 @@
 			buf.putShort(10, (short)256);
 	}
 
+
+	@Override
+    public void stopReceiverTask() {
+	    super.stopReceiverTask();
+	    inflater = new Inflater();
+	}
 }
 
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java	Thu May 22 22:03:14 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java	Fri May 23 01:45:06 2014 +0900
@@ -225,9 +225,10 @@
 	 */
 	public void changeVNCServer(String hostName, int width, int height)
 			throws UnknownHostException, IOException, InterruptedException {
-		// sender and reader stop
+		// stop reader stop
+	    myRfb.stopReceiverTask();
 		inhelitClients(this, hostName);
-		orderRecconection(this, hostName);
+		orderRecconection(hostName);
 	}
 
 	
@@ -241,9 +242,9 @@
 		firstTime = flag;
 	}
 	
-	public void orderRecconection(VncProxyService vps,String hostName) throws UnknownHostException, IOException, InterruptedException {
-		vps.myRfb.waitForReady(this);
-		vps.myRfb.sendDesktopSizeChange();
+	public void orderRecconection(String hostName) throws UnknownHostException, IOException, InterruptedException {
+		myRfb.waitForReady(this);
+		myRfb.sendDesktopSizeChange();
 	}
 
 	public  LinkedList<String> clientList() {