From 12c358230645ca37e438941f61ff00acfe251c54 Mon Sep 17 00:00:00 2001 From: "Brian P. Hinz" Date: Thu, 13 Nov 2014 21:21:25 -0500 Subject: [PATCH] Make sure sockets are shutdown in java viewer listen mode The finalizer method may not be strictly necessary but for the sake of consistency shutdown the socket listener the same way we do for a regular TcpSocket. --- java/com/tigervnc/network/SocketListener.java | 2 +- java/com/tigervnc/network/TcpListener.java | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/java/com/tigervnc/network/SocketListener.java b/java/com/tigervnc/network/SocketListener.java index 6401c2cc..a1f5ea1b 100644 --- a/java/com/tigervnc/network/SocketListener.java +++ b/java/com/tigervnc/network/SocketListener.java @@ -29,7 +29,7 @@ abstract public class SocketListener { public SocketListener() {} // shutdown() stops the socket from accepting further connections - abstract public void shutdown(); + abstract public void shutdown() throws Exception; // accept() returns a new Socket object if there is a connection // attempt in progress AND if the connection passes the filter diff --git a/java/com/tigervnc/network/TcpListener.java b/java/com/tigervnc/network/TcpListener.java index b66558b9..6170a602 100644 --- a/java/com/tigervnc/network/TcpListener.java +++ b/java/com/tigervnc/network/TcpListener.java @@ -84,12 +84,21 @@ public class TcpListener extends SocketListener { this(listenaddr, port, false, null, true); } -// TcpListener::~TcpListener() { -// if (closeFd) closesocket(fd); -// } + protected void finalize() throws Exception { + if (closeFd) + try { + ((SocketDescriptor)getFd()).close(); + } catch (IOException e) { + throw new Exception(e.getMessage()); + } + } - public void shutdown() { - //shutdown(getFd(), 2); + public void shutdown() throws Exception { + try { + ((SocketDescriptor)getFd()).shutdown(); + } catch (IOException e) { + throw new Exception(e.getMessage()); + } } public TcpSocket accept() { -- 2.39.5