Пример #1
0
 private void CreateSendRecieveChannels()
 {
     this.noneSendChannel               = new SendChannel(SendOptions.None, sendDatagramsPool);
     this.inOrderSendChannel            = new SendChannel(SendOptions.InOrder, sendDatagramsPool);
     this.reliableSendChannel           = new SendChannel(SendOptions.Reliable, sendDatagramsPool);
     this.reliableInOrderSendChannel    = new SendChannel(SendOptions.ReliableInOrder, sendDatagramsPool);
     this.noneReceiveChannel            = new ReceiveChannel(SendOptions.None, this.localPeer, this);
     this.inOrderReceiveChannel         = new ReceiveChannel(SendOptions.InOrder, this.localPeer, this);
     this.reliableReceiveChannel        = new ReceiveChannel(SendOptions.Reliable, this.localPeer, this);
     this.reliableInOrderReceiveChannel = new ReceiveChannel(SendOptions.ReliableInOrder, this.localPeer, this);
 }
Пример #2
0
        // used for internal sends that need to be sent immediatly only
        internal bool ForceFlushSendChannelNow(SendOptions channelType)
        {
            SendChannel channel = null;

            switch (channelType)
            {
            case SendOptions.None: channel = noneSendChannel; break;

            case SendOptions.InOrder: channel = inOrderSendChannel; break;

            case SendOptions.Reliable: channel = reliableSendChannel; break;

            case SendOptions.ReliableInOrder: channel = reliableInOrderSendChannel; break;
            }

            return(TryFlushSendChannel(channel));
        }
Пример #3
0
        private bool TryFlushSendChannel(SendChannel channel)
        {
            if (!channel.HasDataToSend)
            {
                return(true);
            }

            Queue <Datagram> queue = channel.GetQueue();

            while (queue.Count > 0)
            {
                Datagram datagram = queue.Dequeue();

                if (channel.IsReliable)
                {
                    if (datagram.IsResend)
                    {
                        // update the time sent
                        datagram.EllapsedSecondsSincePacketSent = 0.0f;
                    }
                    else // i.e. not a re-send
                    {
                        // Save to this reliable send to measure ACK response time and
                        // in case needs re-sending.
                        sentDatagramsAwaitingACK.Add(datagram);
                    }
                }

                // append any ACKs awaiting to be sent that will fit in datagram
                if (enqueudAcks.Count > 0)
                {
                    WriteEnquedAcksToDatagram(datagram, datagram.Offset + datagram.Count);
                }

                bool success = TrySendDatagram(datagram);
                if (!success)
                {
                    return(false);
                }
            } // while

            return(true);
        }