Read and decrypt bytes from the underlying SSL connections. All
the SSLEngine operations are delegated to class SSLUtils
.
final SSLWorkerThread workerThread =
(SSLWorkerThread)Thread.currentThread();
byteBuffer.compact();
int initialPosition = byteBuffer.position();
int byteRead = 0;
// We need to make sure the unwrap worked properly and we have all
// the packets properly read. If the SSLEngine fail to unwrap all the
// bytes, the byteBuffer will be empty event if some encrypted bytes
// are available.
while (byteBuffer.position() == initialPosition){
int currentRead = SSLUtils.doHandshakeRead(key,workerThread.getInputBB(),
workerThread.getSSLEngine(),readTimeout);
if (currentRead > 0) {
byteRead += currentRead;
}
if (currentRead > 0 || workerThread.getInputBB().position() > 0) {
try{
byteBuffer = SSLUtils.unwrapAll(byteBuffer,
workerThread.getInputBB(),workerThread.getSSLEngine());
workerThread.setByteBuffer(byteBuffer);
} catch (IOException ex){
Logger logger = SSLSelectorThread.logger();
if ( logger.isLoggable(Level.FINE) )
logger.log(Level.FINE,"SSLUtils.unwrapAll",ex);
return -1;
}
} else {
break;
}
}
byteBuffer.flip();
return byteRead;