{
m_outNetData.clear();
engineResult = m_engine.wrap(dummy, m_outNetData);
s_logger.dump(engineResult);
Status engineStatus = engineResult.getStatus();
if (engineStatus == Status.OK)
{
// normal
m_outNetData.flip();
hsStatus = engineResult.getHandshakeStatus();
}
else if (engineStatus == Status.CLOSED)
{
m_nState = STATE_CLOSED;
break;
}
else
{
// unexpected handshake status
throw new IOException("Unexpected SSL engine status after call to wrap(). Expected "
+ Status.OK + ", got " + engineStatus);
}
// write data to socket
flushData();
}
else if (hsStatus == HandshakeStatus.NEED_UNWRAP)
{
int n = m_socketChannel.read(m_inNetData);
if (n < 0)
{
// EOF, so set to closed
m_nState = STATE_CLOSED;
break;
}
else if (n == 0 && m_inNetData.position() == 0)
{
// No data to unwrap
break;
}
ByteBuffer tmpAppData = ByteBuffer.allocate(m_engine.getSession().getApplicationBufferSize());
Status engineStatus;
m_inNetData.flip();
tmpAppData.clear();
do