Exemple #1
0
 public void Set(PacketQueueInfo other)
 {
     if (other != null)
     {
         IncomingPacketQueueMaxSizeBytes       = other.IncomingPacketQueueMaxSizeBytes;
         IncomingPacketQueueCurrentSizeBytes   = other.IncomingPacketQueueCurrentSizeBytes;
         IncomingPacketQueueCurrentPacketCount = other.IncomingPacketQueueCurrentPacketCount;
         OutgoingPacketQueueMaxSizeBytes       = other.OutgoingPacketQueueMaxSizeBytes;
         OutgoingPacketQueueCurrentSizeBytes   = other.OutgoingPacketQueueCurrentSizeBytes;
         OutgoingPacketQueueCurrentPacketCount = other.OutgoingPacketQueueCurrentPacketCount;
     }
 }
        /// <summary>
        /// Gets the current cached information related to the incoming and outgoing packet queues.
        /// </summary>
        /// <param name="options">Information about what version of the <see cref="GetPacketQueueInfo" /> API is supported</param>
        /// <param name="outPacketQueueInfo">The current information of the incoming and outgoing packet queues</param>
        /// <returns>
        /// <see cref="Result" />::<see cref="Result.Success" /> - if the input options were valid
        /// <see cref="Result" />::<see cref="Result.InvalidParameters" /> - if the input was invalid in some way
        /// </returns>
        public Result GetPacketQueueInfo(GetPacketQueueInfoOptions options, out PacketQueueInfo outPacketQueueInfo)
        {
            System.IntPtr optionsAddress = new System.IntPtr();
            Helper.TryMarshalSet <GetPacketQueueInfoOptionsInternal, GetPacketQueueInfoOptions>(ref optionsAddress, options);

            var outPacketQueueInfoInternal = Helper.GetDefault <PacketQueueInfoInternal>();

            var funcResult = EOS_P2P_GetPacketQueueInfo(InnerHandle, optionsAddress, ref outPacketQueueInfoInternal);

            Helper.TryMarshalDispose(ref optionsAddress);

            Helper.TryMarshalGet(outPacketQueueInfoInternal, out outPacketQueueInfo);

            return(funcResult);
        }
        private unsafe void SendQueue()
        {
            lock (packetQueue)
            {
                if (packetQueue.Count == 0)
                {
                    return;
                }

                PayloadWriter   pw            = new PayloadWriter();
                PacketQueueInfo currentData   = null;
                PacketQueueInfo compareBuffer = null;
                Stopwatch       sw            = Stopwatch.StartNew();

                while (packetQueue.Count > 0 && sw.ElapsedMilliseconds < this.MaxProcessingTime)
                {
                    while (packetQueue.Count > 0)
                    {
                        if (currentData == null)
                        {
                            currentData  = packetQueue.Dequeue();
                            sizeCounter -= currentData.Payload.Length;
                            continue;
                        }

                        if (currentData.Duplicates == 255)
                        {
                            break;
                        }

                        compareBuffer = packetQueue.Peek();

                        if (compareBuffer.Payload.Length == currentData.Payload.Length || compareBuffer.MessageId != currentData.MessageId)
                        {
                            fixed(byte *ptr1 = currentData.Payload, ptr2 = compareBuffer.Payload)
                            {
                                if (NativeMethods.memcmp(ptr1, ptr2, (uint)currentData.Payload.Length) == 0)
                                {
                                    currentData.Duplicates++;
                                    sizeCounter -= compareBuffer.Payload.Length;
                                    packetQueue.Dequeue();
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    pw.WriteBytes(currentData.ToByteArray());
                    currentData   = null;
                    compareBuffer = null;

                    if (pw.Length > 65535)
                    {
                        break;
                    }
                }

                conn.SendPayload(new MsgPacketQueue(pw.ToByteArray()), PacketId.PacketQueue);
                pw = null;
                sw.Stop();
            }
        }