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);
}
}
+ 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");
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();
}
// 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;
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;
// 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());
}
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)) {