# HG changeset patch # User oc # Date 1423188513 -32400 # Node ID 49e25659ad05263e0f7b6f983f845bcfd1c8f2d8 # Parent dff2f92ae3ff71a7acf05f84d46faead6a8de365 remove socketClose, close unused viewer -d mode. diff -r dff2f92ae3ff -r 49e25659ad05 src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java Thu Feb 05 17:57:47 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java Fri Feb 06 11:08:33 2015 +0900 @@ -47,7 +47,6 @@ } catch (IOException e) { System.out.println("cannot create FindRoot socket."); e.printStackTrace(); - socketClose(); } } @@ -72,7 +71,6 @@ } catch (IOException e) { System.out.println("cannot send FindRoot packet."); e.printStackTrace(); - socketClose(); } } @@ -84,10 +82,7 @@ void socketClose() { try { rootSelectionPanel.unVisible(); - if (is != null) - is.close(); - if (soc != null) - soc.close(); + is.close(); } catch (IOException e) { e.printStackTrace(); System.out.println("cannot is close."); @@ -122,11 +117,9 @@ rootSelectionPanel.checkBox(proxyAddr2); rootSelectionPanel.setButton(); rootSelectionPanel.visible(); - setStopFlag(true); } } catch (IOException e) { System.out.println("an I/O error occurs " + e.getMessage()); - socketClose(); } } diff -r dff2f92ae3ff -r 49e25659ad05 src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Thu Feb 05 17:57:47 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Fri Feb 06 11:08:33 2015 +0900 @@ -202,6 +202,7 @@ // case of root node. if (isTreeManager()) { if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { + viewer.setVisible(false); if (permitChangeScreen()) { ByteBuffer buf = ByteBuffer.wrap(b); buf.order(ByteOrder.BIG_ENDIAN); @@ -501,9 +502,11 @@ } sendDesktopSizeChange(reconnectingId); reconnecting = false; + /* if (reconnectingId == 0) { viewer.setVisible(false); } + */ } if (reconnectingId!=0) { readyReconnect = ready; @@ -642,7 +645,7 @@ * @throws IOException */ public int unzip(Inflater inflater, LinkedList inputs, - int inputIndex, byte[] bytes, int bufSize) { + int inputIndex, byte[] bytes, int bufSize) throws DataFormatException { int position = 0; int limit = bytes.length; while (inputIndex < inputs.size()) { @@ -653,14 +656,10 @@ // inflater.end(); but this won't work do { int len0; - try { len0 = inflater.inflate(bytes, position, limit-position); if (len0 > 0) { position += len0; if (position > limit) throw new DataFormatException(); - } - } catch (DataFormatException e) { - e.printStackTrace(); } } while (!inflater.needsInput()); } @@ -729,6 +728,8 @@ } } catch (IOException e) { throw new TransportException(e); + } catch (DataFormatException e) { + throw new TransportException(e); } return; } diff -r dff2f92ae3ff -r 49e25659ad05 src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Thu Feb 05 17:57:47 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Fri Feb 06 11:08:33 2015 +0900 @@ -79,45 +79,37 @@ } public void sendWithHostAndPort(TreeCommand command, String hostname, int port, short value) throws IOException { - openport(); - if (hostname == null) { - // in case of root finder, we can't get localaddress from datagram packet. - // so use local part of TCP socket. - hostname = echoSocket.getLocalAddress().getHostAddress(); - } - int cmdlen = 4 + 4 + 4 + hostname.length(); - if (cmdlen < 12) cmdlen = 12; - ByteBuffer buf = ByteBuffer.allocate(cmdlen); - buf.order(ByteOrder.BIG_ENDIAN); - buf.put((byte) command.cmd); - buf.put((byte) 0); - buf.putShort(value); - buf.putInt(4 + hostname.length()); // length - buf.putInt(port); - buf.put(hostname.getBytes(), 0, hostname.length()); - while (buf.hasRemaining()) buf.put((byte) 0); - buf.flip(); - sendCommandToTheRoot(buf); + openport(); + if (hostname == null) { + // in case of root finder, we can't get localaddress from datagram packet. + // so use local part of TCP socket. + hostname = echoSocket.getLocalAddress().getHostAddress(); + } + int cmdlen = 4 + 4 + 4 + hostname.length(); + if (cmdlen < 12) cmdlen = 12; + ByteBuffer buf = ByteBuffer.allocate(cmdlen); + buf.order(ByteOrder.BIG_ENDIAN); + buf.put((byte) command.cmd); + buf.put((byte) 0); + buf.putShort(value); + buf.putInt(4 + hostname.length()); // length + buf.putInt(port); + buf.put(hostname.getBytes(), 0, hostname.length()); + while (buf.hasRemaining()) buf.put((byte) 0); + buf.flip(); + sendCommandToTheRoot(buf); } public void sendCommandToTheRoot(ByteBuffer buf) throws IOException { char[] charBuf = new char[12]; - is.read(charBuf, 0, 12); // skip root's version header - os.write(buf.array(), 0, buf.limit()); // send our command + is.read(charBuf, 0, 12); // skip root's version header + os.write(buf.array(), 0, buf.limit()); // send our command } - void streamClose() { - try { - if (os != null) - os.close(); - if (is != null) - is.close(); - if (echoSocket != null) - echoSocket.close(); - } catch (IOException e) { - e.printStackTrace(); - System.out.println("cannot close stream."); - } + void streamClose() throws IOException { + os.close(); + is.close(); + echoSocket.close(); }