@@ -126,7 +126,7 @@ public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorSer
126126 createBuffers (sslEngine .getSession ());
127127 // kick off handshake
128128 socketChannel .write (wrap (emptybuffer ));// initializes res
129- processHandshake ();
129+ processHandshake (false );
130130 }
131131
132132 private void consumeFutureUninterruptible (Future <?> f ) {
@@ -148,7 +148,7 @@ private void consumeFutureUninterruptible(Future<?> f) {
148148 * This method will do whatever necessary to process the sslEngine handshake. Thats why it's
149149 * called both from the {@link #read(ByteBuffer)} and {@link #write(ByteBuffer)}
150150 **/
151- private synchronized void processHandshake () throws IOException {
151+ private synchronized void processHandshake (boolean isReading ) throws IOException {
152152 if (sslEngine .getHandshakeStatus () == HandshakeStatus .NOT_HANDSHAKING ) {
153153 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.
154154 }
@@ -167,7 +167,7 @@ private synchronized void processHandshake() throws IOException {
167167 }
168168 }
169169
170- if (sslEngine .getHandshakeStatus () == SSLEngineResult .HandshakeStatus .NEED_UNWRAP ) {
170+ if (isReading && sslEngine .getHandshakeStatus () == SSLEngineResult .HandshakeStatus .NEED_UNWRAP ) {
171171 if (!isBlocking () || readEngineResult .getStatus () == Status .BUFFER_UNDERFLOW ) {
172172 inCrypt .compact ();
173173 int read = socketChannel .read (inCrypt );
@@ -273,7 +273,7 @@ protected void createBuffers(SSLSession session) {
273273
274274 public int write (ByteBuffer src ) throws IOException {
275275 if (!isHandShakeComplete ()) {
276- processHandshake ();
276+ processHandshake (false );
277277 return 0 ;
278278 }
279279 // assert(bufferallocations > 1); // see #190
@@ -303,10 +303,10 @@ public int read(ByteBuffer dst) throws IOException {
303303 if (!isHandShakeComplete ()) {
304304 if (isBlocking ()) {
305305 while (!isHandShakeComplete ()) {
306- processHandshake ();
306+ processHandshake (true );
307307 }
308308 } else {
309- processHandshake ();
309+ processHandshake (true );
310310 if (!isHandShakeComplete ()) {
311311 return 0 ;
312312 }
0 commit comments