|
5 | 5 | */ |
6 | 6 | package org.java_websocket; |
7 | 7 |
|
| 8 | +import javax.net.ssl.SSLEngine; |
| 9 | +import javax.net.ssl.SSLEngineResult; |
| 10 | +import javax.net.ssl.SSLEngineResult.HandshakeStatus; |
| 11 | +import javax.net.ssl.SSLEngineResult.Status; |
| 12 | +import javax.net.ssl.SSLException; |
| 13 | +import javax.net.ssl.SSLSession; |
| 14 | +import java.io.EOFException; |
8 | 15 | import java.io.IOException; |
9 | 16 | import java.net.Socket; |
10 | 17 | import java.net.SocketAddress; |
|
20 | 27 | import java.util.concurrent.ExecutorService; |
21 | 28 | import java.util.concurrent.Future; |
22 | 29 |
|
23 | | -import javax.net.ssl.SSLEngine; |
24 | | -import javax.net.ssl.SSLEngineResult; |
25 | | -import javax.net.ssl.SSLEngineResult.HandshakeStatus; |
26 | | -import javax.net.ssl.SSLEngineResult.Status; |
27 | | -import javax.net.ssl.SSLException; |
28 | | -import javax.net.ssl.SSLSession; |
29 | | - |
30 | 30 | /** |
31 | 31 | * Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper. |
32 | 32 | */ |
@@ -213,6 +213,9 @@ public int write( ByteBuffer src ) throws IOException { |
213 | 213 | // createBuffers( sslEngine.getSession() ); |
214 | 214 | //} |
215 | 215 | int num = socketChannel.write( wrap( src ) ); |
| 216 | + if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) { |
| 217 | + throw new EOFException("Connection is closed"); |
| 218 | + } |
216 | 219 | return num; |
217 | 220 |
|
218 | 221 | } |
@@ -286,6 +289,9 @@ private int readRemaining( ByteBuffer dst ) throws SSLException { |
286 | 289 | if( inCrypt.hasRemaining() ) { |
287 | 290 | unwrap(); |
288 | 291 | int amount = transfereTo( inData, dst ); |
| 292 | + if (readEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) { |
| 293 | + return -1; |
| 294 | + } |
289 | 295 | if( amount > 0 ) |
290 | 296 | return amount; |
291 | 297 | } |
|
0 commit comments