X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Ffcp%2FFcpConnection.java;h=d7ed4bc2438fd88c45d69692502b2888bc08b5b9;hb=930a13cd3640422a0fd23e2952cacf798286f0bc;hp=5757d617a95dc36985d4e7e7faadfc07a933b1f4;hpb=ce478696a8689472c1bd99e4d79eef4d822e4eff;p=jFCPlib.git diff --git a/src/net/pterodactylus/fcp/FcpConnection.java b/src/net/pterodactylus/fcp/FcpConnection.java index 5757d61..d7ed4bc 100644 --- a/src/net/pterodactylus/fcp/FcpConnection.java +++ b/src/net/pterodactylus/fcp/FcpConnection.java @@ -649,11 +649,14 @@ public class FcpConnection implements Closeable { /** * Notifies all listeners that the connection to the node was closed. * - * @see FcpListener#connectionClosed(FcpConnection) + * @param throwable + * The exception that caused the disconnect, or null + * if there was no exception + * @see FcpListener#connectionClosed(FcpConnection, Throwable) */ - private void fireConnectionClosed() { + private void fireConnectionClosed(Throwable throwable) { for (FcpListener fcpListener: fcpListeners) { - fcpListener.connectionClosed(this); + fcpListener.connectionClosed(this, throwable); } } @@ -696,14 +699,7 @@ public class FcpConnection implements Closeable { * does nothing. */ public void close() { - if (connectionHandler == null) { - return; - } - logger.info("disconnecting…"); - FcpUtils.close(remoteSocket); - connectionHandler.stop(); - connectionHandler = null; - fireConnectionClosed(); + handleDisconnect(null); } /** @@ -823,13 +819,20 @@ public class FcpConnection implements Closeable { /** * Handles a disconnect from the node. + * + * @param throwable + * The exception that caused the disconnect, or null + * if there was no exception */ - synchronized void handleDisconnect() { + synchronized void handleDisconnect(Throwable throwable) { FcpUtils.close(remoteInputStream); FcpUtils.close(remoteOutputStream); FcpUtils.close(remoteSocket); - connectionHandler = null; - fireConnectionClosed(); + if (connectionHandler != null) { + connectionHandler.stop(); + connectionHandler = null; + } + fireConnectionClosed(throwable); } //