Improved logging and exception handling.
Now IllegalStateExceptions are thrown with a message. Methods needsFillInterest() and onIncompleteFlush() are now wrapped in try/catch to make sure the connection is closed in case of exceptions. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
a3451c9d6e
commit
ddd80deeb9
|
@ -519,7 +519,7 @@ public class SslConnection extends AbstractConnection
|
|||
return filled = 0;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("Unexpected HandshakeStatus " + status);
|
||||
}
|
||||
|
||||
if (_encryptedInput==null)
|
||||
|
@ -616,7 +616,7 @@ public class SslConnection extends AbstractConnection
|
|||
}
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("Unexpected unwrap result " + unwrap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -659,6 +659,8 @@ public class SslConnection extends AbstractConnection
|
|||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug(SslConnection.this.toString(), x);
|
||||
close(x);
|
||||
throw x;
|
||||
}
|
||||
|
@ -666,6 +668,8 @@ public class SslConnection extends AbstractConnection
|
|||
|
||||
@Override
|
||||
protected void needsFillInterest()
|
||||
{
|
||||
try
|
||||
{
|
||||
boolean fillable;
|
||||
ByteBuffer write = null;
|
||||
|
@ -684,7 +688,8 @@ public class SslConnection extends AbstractConnection
|
|||
// Fillable if we have decrypted Input OR encrypted input that has not yet been underflown.
|
||||
fillable = BufferUtil.hasContent(_decryptedInput) || (BufferUtil.hasContent(_encryptedInput) && !_underflown);
|
||||
|
||||
switch(_sslEngine.getHandshakeStatus())
|
||||
HandshakeStatus status = _sslEngine.getHandshakeStatus();
|
||||
switch (status)
|
||||
{
|
||||
case NEED_TASK:
|
||||
// Pretend we are fillable
|
||||
|
@ -703,7 +708,6 @@ public class SslConnection extends AbstractConnection
|
|||
case NEED_WRAP:
|
||||
if (!fillable)
|
||||
{
|
||||
fillable = false;
|
||||
_fillState = FillState.WAIT_FOR_FLUSH;
|
||||
if (_flushState == FlushState.IDLE)
|
||||
{
|
||||
|
@ -714,7 +718,7 @@ public class SslConnection extends AbstractConnection
|
|||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("Unexpected HandshakeStatus " + status);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
|
@ -728,6 +732,14 @@ public class SslConnection extends AbstractConnection
|
|||
else if (interest)
|
||||
ensureFillInterested();
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug(SslConnection.this.toString(), x);
|
||||
close(x);
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
|
||||
private void handshakeSucceeded()
|
||||
{
|
||||
|
@ -839,7 +851,7 @@ public class SslConnection extends AbstractConnection
|
|||
return result = false;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("Unexpected HandshakeStatus " + status);
|
||||
}
|
||||
|
||||
if (_encryptedOutput == null)
|
||||
|
@ -867,13 +879,16 @@ public class SslConnection extends AbstractConnection
|
|||
allConsumed=false;
|
||||
|
||||
// if we have net bytes, let's try to flush them
|
||||
boolean flushed = BufferUtil.hasContent(_encryptedOutput) ? getEndPoint().flush(_encryptedOutput) : true;
|
||||
boolean flushed = true;
|
||||
if (BufferUtil.hasContent(_encryptedOutput))
|
||||
flushed = getEndPoint().flush(_encryptedOutput);
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("net flushed={}, ac={}", flushed, allConsumed);
|
||||
|
||||
// Now deal with the results returned from the wrap
|
||||
switch (wrapResult.getStatus())
|
||||
Status wrap = wrapResult.getStatus();
|
||||
switch (wrap)
|
||||
{
|
||||
case CLOSED:
|
||||
{
|
||||
|
@ -911,7 +926,7 @@ public class SslConnection extends AbstractConnection
|
|||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("Unexpected wrap result " + wrap);
|
||||
}
|
||||
|
||||
if (getEndPoint().isOutputShutdown())
|
||||
|
@ -933,6 +948,8 @@ public class SslConnection extends AbstractConnection
|
|||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug(SslConnection.this.toString(), x);
|
||||
close(x);
|
||||
throw x;
|
||||
}
|
||||
|
@ -940,6 +957,8 @@ public class SslConnection extends AbstractConnection
|
|||
|
||||
@Override
|
||||
protected void onIncompleteFlush()
|
||||
{
|
||||
try
|
||||
{
|
||||
boolean fillInterest = false;
|
||||
ByteBuffer write = null;
|
||||
|
@ -1006,7 +1025,7 @@ public class SslConnection extends AbstractConnection
|
|||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("Unexpected HandshakeStatus " + status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1020,6 +1039,14 @@ public class SslConnection extends AbstractConnection
|
|||
else if (fillInterest)
|
||||
ensureFillInterested();
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug(SslConnection.this.toString(), x);
|
||||
close(x);
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doShutdownOutput()
|
||||
|
|
Loading…
Reference in New Issue