private bool WriteSend(EndpointManager.Send send)
{
try
{
if (_handle == null)
throw new EndpointException(
"Internal error: Endpoint is in state Writing, but no association handle is present.");
if (_provider.RemoteSettings.LogSend)
{
_log.Debug("RemoteMessage: {0} to [{1}]<+[{2}] from [{3}]", send.Message,
send.Recipient, send.Recipient.Path, send.SenderOption ?? _system.DeadLetters);
}
var pdu = _codec.ConstructMessage(send.Recipient.LocalAddressToUse, send.Recipient,
SerializeMessage(send.Message), send.SenderOption, send.Seq, _lastAck);
_remoteMetrics.LogPayloadBytes(send.Message, pdu.Length);
if (pdu.Length > Transport.MaximumPayloadBytes)
{
var reason = new OversizedPayloadException(
string.Format("Discarding oversized payload sent to {0}: max allowed size {1} bytes, actual size of encoded {2} was {3} bytes.",
send.Recipient,
Transport.MaximumPayloadBytes,
send.Message.GetType(),
pdu.Length));
_log.Error(reason, "Transient association error (association remains live)");
return true;
}
else
{
var ok = _handle.Write(pdu);
if (ok)
{
_ackDeadline = NewAckDeadline();
_lastAck = null;
return true;
}
}
return false;
}
catch (SerializationException ex)
{
_log.Error(ex, "Transient association error (association remains live)");
return true;
}
catch (EndpointException ex)
{
PublishAndThrow(ex, LogLevel.ErrorLevel);
}
catch (Exception ex)
{
PublishAndThrow(new EndpointException("Failed to write message to the transport", ex),
LogLevel.ErrorLevel);
}
return false;
}