private void Reading()
{
Receive<Disassociated>(disassociated => HandleDisassociated(disassociated.Info));
Receive<InboundPayload>(inbound =>
{
var payload = inbound.Payload;
if (payload.Length > Transport.MaximumPayloadBytes)
{
var reason = new OversizedPayloadException(
string.Format("Discarding oversized payload received: max allowed size {0} bytes, actual size {1} bytes.",
Transport.MaximumPayloadBytes,
payload.Length));
_log.Error(reason, "Transient error while reading from association (association remains live)");
}
else
{
var ackAndMessage = TryDecodeMessageAndAck(payload);
if (ackAndMessage.AckOption != null && _reliableDeliverySupervisor != null)
_reliableDeliverySupervisor.Tell(ackAndMessage.AckOption);
if (ackAndMessage.MessageOption != null)
{
if (ackAndMessage.MessageOption.ReliableDeliveryEnabled)
{
_ackedReceiveBuffer = _ackedReceiveBuffer.Receive(ackAndMessage.MessageOption);
DeliverAndAck();
}
else
{
_msgDispatch.Dispatch(ackAndMessage.MessageOption.Recipient,
ackAndMessage.MessageOption.RecipientAddress,
ackAndMessage.MessageOption.SerializedMessage,
ackAndMessage.MessageOption.SenderOptional);
}
}
}
});
Receive<EndpointWriter.StopReading>(stop =>
{
SaveState();
Become(NotReading);
stop.ReplyTo.Tell(new EndpointWriter.StoppedReading(stop.Writer));
});
}