diff --git a/src/main/java/org/ice4j/socket/DelegatingDatagramSocket.java b/src/main/java/org/ice4j/socket/DelegatingDatagramSocket.java index 7449864..db1984b 100644 --- a/src/main/java/org/ice4j/socket/DelegatingDatagramSocket.java +++ b/src/main/java/org/ice4j/socket/DelegatingDatagramSocket.java @@ -115,6 +115,11 @@ public class DelegatingDatagramSocket */ private long nbSentPackets = 0; + /** + * Whether this socket has been closed. + */ + private boolean closed = false; + /** * Initializes a new DelegatingDatagramSocket instance and binds it * to any available port on the local host machine. The socket will be @@ -282,10 +287,14 @@ public class DelegatingDatagramSocket @Override public void close() { + // We want both #delegate and super to actually get closed (and release + // the FDs which they hold). But super will not close unless isClosed() + // returns false. So we update the #closed flag last. if (delegate != null) delegate.close(); super.close(); + closed = true; } /** @@ -610,7 +619,7 @@ public class DelegatingDatagramSocket @Override public boolean isClosed() { - return (delegate == null) ? super.isClosed() : delegate.isClosed(); + return closed; } /**