Mercurial > hg > Applications > TreeVNC
changeset 160:b9052986bbb3
fix command loop.
author | oc |
---|---|
date | Mon, 16 Jun 2014 19:20:05 +0900 |
parents | 1c9f6acdfeb2 |
children | e997deb54314 |
files | src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java |
diffstat | 3 files changed, 26 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Sat Jun 14 09:22:52 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Mon Jun 16 19:20:05 2014 +0900 @@ -208,7 +208,9 @@ writerRunning.set(2); os.close(); } catch (IOException e1) { + System.out.println("root writer close faild :" + e1); } + System.out.println("root writer faild :" + e); /* if socket closed cliList.remove(newCli); */ } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java Sat Jun 14 09:22:52 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java Mon Jun 16 19:20:05 2014 +0900 @@ -117,6 +117,10 @@ private void handleLostParent(int port, String hostname) { rfb.viewer.fixLostParent(hostname,port); } + + public TreeCommand getCommand () { + return command; + } } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java Sat Jun 14 09:22:52 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java Mon Jun 16 19:20:05 2014 +0900 @@ -2,7 +2,8 @@ import java.net.Socket; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -18,7 +19,7 @@ public MyRfbProto rfb = null; byte[] imageBytes; int port; - LinkedBlockingDeque<TreeVncCommand> cmdQueue = new LinkedBlockingDeque<TreeVncCommand>(); + LinkedBlockingQueue<TreeVncCommand> cmdQueue = new LinkedBlockingQueue<TreeVncCommand>(); private Thread acceptThread; protected final static String versionMsg_3_856 = "RFB 003.856\n"; @@ -29,16 +30,23 @@ } public void commandMainLoop() { - acceptThread = new Thread(new Runnable() { - @Override - public void run() { - TreeVncCommand cmd; - do { - cmd = cmdQueue.poll(); - cmd.handleTreeVncCommand(); - } while (cmd!=null); - } - },"root-command-loop"); + acceptThread = new Thread(new Runnable() { + @Override + public void run() { + TreeVncCommand cmd = null; + do { + try { + cmd = cmdQueue.poll(0, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + continue; + } + if (cmd!=null) { + cmd.handleTreeVncCommand(); + } + } while (cmd == null || cmd.getCommand() != TreeCommand.QUIT_LOOP); + } + },"root-command-loop"); + acceptThread.start(); } public void run() {