Пример #1
0
 public void Enqueue(NetworkMessage msg)
 {
     if (isResetPending && msg.IsGuaranteed)
     {
         if (IsVerbose)
             NeutrinoConfig.Log(node.Name + " reset pending enqueuing for later: " + msg);
         byte[] buffer = new byte[NeutrinoConfig.MaxMessageSize];
         msg.Write(buffer);
         pendingResetOutboundMessages.Add(buffer);
     }
     else
     {
         var outboundMessage = outboundMessagePool.Pop();
         Assign(msg, outboundMessage);
         outboundMessages.Add(outboundMessage);
     }
 }
Пример #2
0
 public void SendNetworkMessage(NetworkMessage msg)
 {
     outboundQueue.Enqueue(msg);
 }
Пример #3
0
 private void Assign(NetworkMessage msg, OutboundMessage target)
 {
     target.ContainedMessageType = msg.GetType();
     if (msg.IsGuaranteed)
     {
         target.SequenceNumber = nextSequence++;
         outboundMessagesBySequence[target.SequenceNumber] = target;
         msg.SequenceNumber = target.SequenceNumber;
     }
     target.PayloadLength = msg.Write(target.Payload);
     target.NeedsAck = msg.IsGuaranteed;
     target.PreviousSendTicks = Environment.TickCount - resendGuaranteedPeriodTicks - 1;
     if (!(msg is ResetNetworkIdsMessage) && nextSequence == maxGuaranteedBeforeReset)
     {
         if (IsVerbose)
             NeutrinoConfig.Log (node.Name + " reached max sequence - resetting...");
         Enqueue(msgFactory.Get<ResetNetworkIdsMessage>());
         isResetPending = true;
     }
 }
Пример #4
0
 private void ProcessMessage(NetworkMessage msg)
 {
     ResetNetworkIdsMessage resetMsg = msg as ResetNetworkIdsMessage;
     if (resetMsg != null)
     {
         Array.Clear(idempotentSequenceNumbers, 0, idempotentSequenceNumbers.Length);
         if (pendingOutOfSequenceMessages.Count != 0)
         {
             NeutrinoConfig.LogError(node.Name + " there were still pending messages when resetting id's!");
             pendingOutOfSequenceMessages.Clear();
         }
     }
     node.OnReceived(msg);
 }