@@ -249,10 +249,6 @@ private void checkHandshakeTasks(SSLEngine engine) {
249
249
private void needTask () {
250
250
@ SuppressWarnings ("unchecked" )
251
251
List <Task <Void ,NoException >> tasks = (List <Task <Void ,NoException >>)conn .getAttribute (HANDSHAKE_TASKS_ATTRIBUTE );
252
- if (tasks == null || tasks .isEmpty ()) {
253
- followup (conn , timeout );
254
- return ;
255
- }
256
252
MutableBoolean firstTask = new MutableBoolean (true );
257
253
Runnable taskDone = () -> {
258
254
synchronized (firstTask ) {
@@ -265,15 +261,8 @@ private void needTask() {
265
261
return null ;
266
262
}).start ();
267
263
};
268
- for (Iterator <Task <Void ,NoException >> it = tasks .iterator (); it .hasNext (); ) {
269
- Task <Void ,NoException > t = it .next ();
270
- if (t .getOutput ().isDone ()) {
271
- it .remove ();
272
- followup (conn , timeout );
273
- return ;
274
- }
275
- t .getOutput ().onDone (taskDone );
276
- }
264
+ for (Iterator <Task <Void ,NoException >> it = tasks .iterator (); it .hasNext (); )
265
+ it .next ().getOutput ().onDone (taskDone );
277
266
}
278
267
279
268
private void needWrap () {
@@ -334,14 +323,7 @@ private boolean needUnwrap(SSLEngine engine, ByteBuffer inputBuffer, Object inpu
334
323
return true ;
335
324
}
336
325
if (SSLEngineResult .Status .BUFFER_OVERFLOW .equals (result .getStatus ())) {
337
- if (logger .debug ())
338
- logger .debug (
339
- "Cannot unwrap because buffer is too small, enlarge it" );
340
- ByteBuffer b = ByteBuffer .wrap (bufferCache .get (dst .capacity () << 1 , true ));
341
- dst .flip ();
342
- b .put (dst );
343
- bufferCache .free (dst );
344
- dst = b ;
326
+ dst = enlargeBuffer (dst );
345
327
continue ;
346
328
}
347
329
if (logger .debug ())
@@ -450,13 +432,7 @@ private void dataReceived(TCPConnection conn, SSLEngine engine, ByteBuffer input
450
432
return ;
451
433
}
452
434
if (SSLEngineResult .Status .BUFFER_OVERFLOW .equals (result .getStatus ())) {
453
- if (logger .debug ())
454
- logger .debug ("Output buffer too small to decrypt data, try again with larger one" );
455
- ByteBuffer b = ByteBuffer .wrap (bufferCache .get (dst .capacity () << 1 , true ));
456
- dst .flip ();
457
- b .put (dst );
458
- bufferCache .free (dst );
459
- dst = b ;
435
+ dst = enlargeBuffer (dst );
460
436
continue ;
461
437
}
462
438
// data ready
@@ -480,6 +456,14 @@ private void compactInputBuffer(ByteBuffer inputBuffer, int packetSize, TCPConne
480
456
inputBuffer .compact ();
481
457
}
482
458
459
+ private ByteBuffer enlargeBuffer (ByteBuffer buf ) {
460
+ ByteBuffer b = ByteBuffer .wrap (bufferCache .get (buf .capacity () << 1 , true ));
461
+ buf .flip ();
462
+ b .put (buf );
463
+ bufferCache .free (buf );
464
+ return b ;
465
+ }
466
+
483
467
/** Encrypt the given data. */
484
468
@ SuppressWarnings ("squid:S1319" ) // return LinkedList instead of List
485
469
public LinkedList <ByteBuffer > encryptDataToSend (TCPConnection conn , List <ByteBuffer > data ) throws SSLException {
@@ -512,11 +496,7 @@ public LinkedList<ByteBuffer> encryptDataToSend(TCPConnection conn, List<ByteBuf
512
496
continue ;
513
497
}
514
498
packetSize <<= 1 ;
515
- ByteBuffer b = ByteBuffer .wrap (bufferCache .get (dst .capacity () << 1 , true ));
516
- dst .flip ();
517
- b .put (dst );
518
- bufferCache .free (dst );
519
- dst = b ;
499
+ dst = enlargeBuffer (dst );
520
500
continue ;
521
501
}
522
502
if (!toEncrypt .hasRemaining ()) {
0 commit comments