Endless loop in client upon close() when using wss
First, thanks so much for creating the library, it's really useful. I am using this via gottox/socket-io (client) and have run into this nasty problem of an endless loop in SSLSocketChannel2.java when closing a connection (maybe after the other side closed first). A couple of these failures is all it takes to pin the CPU at 100% as the threads that execute these loops pile up.

I doubt this is the correct fix, but what I did was change the following in SSLSocketChannel2.readRemaining(), which seems to work.

``` java
        if( inCrypt.hasRemaining() ) {
            unwrap();
            int amount = transfereTo( inData, dst );
>>>         if (engineStatus == SSLEngineResult.Status.CLOSED) {
>>>             return -1;
>>>         }
            if( amount > 0 )
                return amount;
        }
```

EDIT by @Davidisudadi: formatted code

diff --git a/src/main/java/org/java_websocket/SSLSocketChannel2.java b/src/main/java/org/java_websocket/SSLSocketChannel2.java
index ba8d8f8..e540612 100644
--- a/src/main/java/org/java_websocket/SSLSocketChannel2.java
+++ b/src/main/java/org/java_websocket/SSLSocketChannel2.java
@@ -5,6 +5,13 @@
  */
 package org.java_websocket;
 
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLEngineResult.HandshakeStatus;
+import javax.net.ssl.SSLEngineResult.Status;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+import java.io.EOFException;
 import java.io.IOException;
 import java.net.Socket;
 import java.net.SocketAddress;
@@ -20,13 +27,6 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLEngineResult;
-import javax.net.ssl.SSLEngineResult.HandshakeStatus;
-import javax.net.ssl.SSLEngineResult.Status;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
-
 /**
  * Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper.
  */
@@ -213,6 +213,9 @@ public class SSLSocketChannel2 implements ByteChannel, WrappedByteChannel {
 		//	createBuffers( sslEngine.getSession() );
 		//}
 		int num = socketChannel.write( wrap( src ) );
+        if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) {
+            throw new EOFException("Connection is closed");
+        }
 		return num;
 
 	}
@@ -286,6 +289,9 @@ public class SSLSocketChannel2 implements ByteChannel, WrappedByteChannel {
 		if( inCrypt.hasRemaining() ) {
 			unwrap();
 			int amount = transfereTo( inData, dst );
+            if (readEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) {
+                return -1;
+            }
 			if( amount > 0 )
 				return amount;
 		}
['src/main/java/org/java_websocket/SSLSocketChannel2.java']