override protected bool HandleIncoming(MemBlock data, out MemBlock app_data)
{
app_data = null;
int count = 0;
lock(_buffer_sync) {
if(data != null) {
data.CopyTo(_buffer, 0);
_read.Write(_buffer, data.Length);
}
count = _ssl.Read(_buffer, _buffer.Length);
if(count > 0) {
app_data = MemBlock.Copy(_buffer, 0, count);
}
}
if(app_data != null) {
// If the read was successful, Dtls has received an incoming data
// message and decrypted it
return true;
} else {
SslError error = _ssl.GetError(count);
if(error == SslError.SSL_ERROR_WANT_READ) {
if(SslState == SslState.OK) {
UpdateState(States.Active);
// In the SslCtx verify, there's no way to get the underlying Sender
_ch.Verify(RemoteCertificate, Sender);
}
HandleWouldBlock();
} else if(error == SslError.SSL_ERROR_SSL) {
var ose = new OpenSslException();
Close("Received unrecoverable error: " + ose.ToString());
throw ose;
} else if(error == SslError.SSL_ERROR_ZERO_RETURN) {
Close("Received clean close notification");
} else {
ProtocolLog.WriteIf(ProtocolLog.SecurityExceptions,
"Receive other: " + error);
}
}
return false;
}