From: Brian P. Hinz Date: Fri, 14 Nov 2014 02:21:25 +0000 (-0500) Subject: Make sure sockets are shutdown in java viewer listen mode X-Git-Tag: v1.3.90~8^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=12c358230645ca37e438941f61ff00acfe251c54;p=tigervnc.git 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. --- 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() {