@@ -126,7 +126,7 @@ public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorSer
126
126
createBuffers (sslEngine .getSession ());
127
127
// kick off handshake
128
128
socketChannel .write (wrap (emptybuffer ));// initializes res
129
- processHandshake ();
129
+ processHandshake (false );
130
130
}
131
131
132
132
private void consumeFutureUninterruptible (Future <?> f ) {
@@ -148,7 +148,7 @@ private void consumeFutureUninterruptible(Future<?> f) {
148
148
* This method will do whatever necessary to process the sslEngine handshake. Thats why it's
149
149
* called both from the {@link #read(ByteBuffer)} and {@link #write(ByteBuffer)}
150
150
**/
151
- private synchronized void processHandshake () throws IOException {
151
+ private synchronized void processHandshake (boolean isReading ) throws IOException {
152
152
if (sslEngine .getHandshakeStatus () == HandshakeStatus .NOT_HANDSHAKING ) {
153
153
return ; // since this may be called either from a reading or a writing thread and because this method is synchronized it is necessary to double check if we are still handshaking.
154
154
}
@@ -167,7 +167,7 @@ private synchronized void processHandshake() throws IOException {
167
167
}
168
168
}
169
169
170
- if (sslEngine .getHandshakeStatus () == SSLEngineResult .HandshakeStatus .NEED_UNWRAP ) {
170
+ if (isReading && sslEngine .getHandshakeStatus () == SSLEngineResult .HandshakeStatus .NEED_UNWRAP ) {
171
171
if (!isBlocking () || readEngineResult .getStatus () == Status .BUFFER_UNDERFLOW ) {
172
172
inCrypt .compact ();
173
173
int read = socketChannel .read (inCrypt );
@@ -273,7 +273,7 @@ protected void createBuffers(SSLSession session) {
273
273
274
274
public int write (ByteBuffer src ) throws IOException {
275
275
if (!isHandShakeComplete ()) {
276
- processHandshake ();
276
+ processHandshake (false );
277
277
return 0 ;
278
278
}
279
279
// assert(bufferallocations > 1); // see #190
@@ -303,10 +303,10 @@ public int read(ByteBuffer dst) throws IOException {
303
303
if (!isHandShakeComplete ()) {
304
304
if (isBlocking ()) {
305
305
while (!isHandShakeComplete ()) {
306
- processHandshake ();
306
+ processHandshake (true );
307
307
}
308
308
} else {
309
- processHandshake ();
309
+ processHandshake (true );
310
310
if (!isHandShakeComplete ()) {
311
311
return 0 ;
312
312
}
0 commit comments