From 8d9c4636668ee1cb37def7a977fe45c6d3909d48 Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Sun, 22 Jul 2012 20:25:57 +0000 Subject: [PATCH] Changes to allow compiling on JDK7 git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4948 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- .../tigervnc/network/SocketDescriptor.java | 25 ++++++++++++++++--- java/com/tigervnc/network/TcpListener.java | 6 ++++- java/com/tigervnc/network/TcpSocket.java | 25 +++++++++++++------ java/com/tigervnc/vncviewer/CConn.java | 3 +-- java/com/tigervnc/vncviewer/F8Menu.java | 2 +- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/java/com/tigervnc/network/SocketDescriptor.java b/java/com/tigervnc/network/SocketDescriptor.java index eb2679d9..3517a99f 100644 --- a/java/com/tigervnc/network/SocketDescriptor.java +++ b/java/com/tigervnc/network/SocketDescriptor.java @@ -29,11 +29,10 @@ import java.util.Iterator; import com.tigervnc.rdr.Exception; -public class SocketDescriptor extends SocketChannel - implements FileDescriptor { +public class SocketDescriptor implements FileDescriptor { public SocketDescriptor() throws Exception { - super(DefaultSelectorProvider()); + DefaultSelectorProvider(); try { channel = SocketChannel.open(); channel.configureBlocking(false); @@ -50,6 +49,14 @@ public class SocketDescriptor extends SocketChannel } } + public void close() throws IOException { + try { + channel.close(); + } catch(IOException e) { + throw new IOException(e.toString()); + } + } + private static SelectorProvider DefaultSelectorProvider() { // kqueue() selector provider on OS X is not working, fall back to select() for now String os = System.getProperty("os.name"); @@ -165,6 +172,18 @@ public class SocketDescriptor extends SocketChannel public java.net.Socket socket() { return channel.socket(); } + + public SocketAddress getRemoteAddress() throws IOException { + if (isConnected()) + return channel.socket().getRemoteSocketAddress(); + return null; + } + + public SocketAddress getLocalAddress() throws IOException { + if (isConnected()) + return channel.socket().getLocalSocketAddress(); + return null; + } public boolean isConnectionPending() { return channel.isConnectionPending(); diff --git a/java/com/tigervnc/network/TcpListener.java b/java/com/tigervnc/network/TcpListener.java index d6e92ab9..959d5459 100644 --- a/java/com/tigervnc/network/TcpListener.java +++ b/java/com/tigervnc/network/TcpListener.java @@ -118,7 +118,11 @@ public class TcpListener extends SocketListener { } // Disable Nagle's algorithm, to reduce latency - TcpSocket.enableNagles(new_sock, false); + try { + new_sock.socket().setTcpNoDelay(true); + } catch (java.net.SocketException e) { + throw new SocketException(e.toString()); + } // Create the socket object & check connection is allowed SocketDescriptor fd = null; diff --git a/java/com/tigervnc/network/TcpSocket.java b/java/com/tigervnc/network/TcpSocket.java index c4c1a8cf..ac53aaf7 100644 --- a/java/com/tigervnc/network/TcpSocket.java +++ b/java/com/tigervnc/network/TcpSocket.java @@ -142,23 +142,32 @@ public class TcpSocket extends Socket { return address+"::"+port; } - public boolean sameMachine() { - SocketAddress peeraddr = ((SocketDescriptor)getFd()).socket().getRemoteSocketAddress(); - SocketAddress myaddr = ((SocketDescriptor)getFd()).socket().getLocalSocketAddress(); - return myaddr.equals(peeraddr); + public boolean sameMachine() throws Exception { + try { + SocketAddress peeraddr = ((SocketDescriptor)getFd()).getRemoteAddress(); + SocketAddress myaddr = ((SocketDescriptor)getFd()).getLocalAddress(); + return myaddr.equals(peeraddr); + } catch (IOException e) { + throw new Exception(e.toString()); + } } - public void shutdown() { - super.shutdown(); + public void shutdown() throws Exception { + try { + close(); + super.shutdown(); + } catch (IOException e) { + throw new Exception(e.toString()); + } } public void close() throws IOException { ((SocketDescriptor)getFd()).close(); } - public static boolean enableNagles(SocketChannel sock, boolean enable) { + public static boolean enableNagles(SocketDescriptor sock, boolean enable) { try { - sock.socket().setTcpNoDelay(!enable); + sock.channel.socket().setTcpNoDelay(!enable); } catch(java.net.SocketException e) { vlog.error("unable to setsockopt TCP_NODELAY: "+e.getMessage()); return false; diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java index 736994b1..2faf787d 100644 --- a/java/com/tigervnc/vncviewer/CConn.java +++ b/java/com/tigervnc/vncviewer/CConn.java @@ -776,9 +776,8 @@ public class CConn extends CConnection // close() closes the socket, thus waking up the RFB thread. public void close() { shuttingDown = true; - sock.shutdown(); try { - sock.close(); + sock.shutdown(); } catch (java.lang.Exception e) { throw new Exception(e.toString()); } diff --git a/java/com/tigervnc/vncviewer/F8Menu.java b/java/com/tigervnc/vncviewer/F8Menu.java index ca09ac20..317caf35 100644 --- a/java/com/tigervnc/vncviewer/F8Menu.java +++ b/java/com/tigervnc/vncviewer/F8Menu.java @@ -85,7 +85,7 @@ public class F8Menu extends JPopupMenu implements ActionListener { public void actionPerformed(ActionEvent ev) { if (actionMatch(ev, exit)) { - cc.close(); + cc.deleteWindow(); } else if (actionMatch(ev, fullScreen)) { cc.toggleFullScreen(); } else if (actionMatch(ev, restore)) { -- 2.39.5