// Helper routine for finalizing message state ready for sending. // If justFree, simply frees message buffer. // If dispatchAction=BabelConstants.SEND_TO_ROUTER, sends message to router. // If dispatchAction=BabelConstants.POST_TO_WRITE, pushes message onto oPort's Write Q. public void FinishMessageTransaction() { if (Finish == FinishAction.Free) { Manager.IoBuffersFreeHeap.Release(IoIndex); } else if (Finish == FinishAction.Keep) { } else { if (ReturnCmd != 0) { MsgBuffer.command(ReturnCmd); } if (ChangeDir) { // Change general message direction: // r<>s, RNetIf<>SNetIf, rPort<>sPort, // Invert Is Reply flag, clear ACK flag byte ports, flags = MsgBuffer.flagsRS(); ushort sender = MsgBuffer.sender(); MsgBuffer.sender(MsgBuffer.receiver()); MsgBuffer.receiver(sender); flags ^= ProtocolConstants.MESSAGE_FLAGS_IS_REPLY; flags &= Primitives.ByteNeg(ProtocolConstants.MESSAGE_FLAGS_ACK); // Now swap ports. ports = (byte)(flags & ProtocolConstants.MESSAGE_PORTS_MASK); ports = (byte)((ports << 2) | (ports >> 2)); MsgBuffer.flagsRS((byte)((ports & ProtocolConstants.MESSAGE_PORTS_MASK) | (flags & ProtocolConstants.MESSAGE_FLAGS_MASK))); } else { // Caller might be relaying message to another adrs:netIf. // So leave flagsRS alone. } MsgBuffer.pktLen = (byte)(ProtocolConstants.GENERAL_OVERHEADS_SIZE + MsgBuffer.dataLength()); MsgBuffer.UpdateCheckSum(MsgBuffer.pktLen); if (Dispatch == Router.RouterAction.SendToRouter) { Router.RouteMessage(Manager, IoIndex); } else if (Dispatch == Router.RouterAction.PostToNetIf) { Router.PostMessage(Manager, IoIndex, ONetIfIndex); } } }