예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PacketEventArgs"/> class.
 /// </summary>
 /// <param name="PacketID">The packet ID.</param>
 /// <param name="RemoteClient">The remote client.</param>
 /// <param name="PacketMode">The packet mode.</param>
 /// <param name="Packet">The packet.</param>
 /// <remarks></remarks>
 public PacketEventArgs(PacketID PacketID, RemoteClient RemoteClient, PacketMode PacketMode, Packet Packet)
 {
     this.PacketID = PacketID;
     this.RemoteClient = RemoteClient;
     this.Handled = false;
     this.Packet = Packet;
 }
예제 #2
0
 public static bool RecreatePacket(
     ref byte[] packet,
     out Int32 offest,
     out Int32 length,
     out byte compression,
     PacketMode mode)
 {
     if (mode == PacketMode.Raw)
     {
         offest      = 0;
         compression = 0;
         return(RecreatePacket_Raw(ref packet, out length));
     }
     else if (mode == PacketMode.Stop)
     {
         offest      = 0;
         compression = 0;
         return(RecreatePacket_Stop(ref packet, out length));
     }
     else if (mode == PacketMode.StartSizeStopCompressSum)
     {
         return(RecreatePacket_StartSizeStopCompressSum(ref packet, out offest, out length, out compression));
     }
     else
     {
         offest      = -1;
         length      = -1;
         compression = 0;
         return(false);
     }
 }
예제 #3
0
 public static IMode GetAckPacket(RequestMode mode, string packetType, string absolutePath, int packetId, string text)
 {
     if (mode == RequestMode.Packet)
     {
         PacketMode packet = new PacketMode(packetType, absolutePath, packetId, text);
         return(packet);
     }
     else if (mode == RequestMode.Payload)
     {
         PacketMode  packet  = new PacketMode(packetType, absolutePath, packetId, text);
         PayloadMode payload = new PayloadMode(packet);
         return(payload);
     }
     else
     {
         return(null);
     }
 }
예제 #4
0
 public static byte[] CreatePacket(byte[] data, PacketMode mode)
 {
     if (mode == PacketMode.Raw)
     {
         return(CreatePacket_Raw(data));
     }
     else if (mode == PacketMode.Stop)
     {
         return(CreatePacket_Stop(data));
     }
     else if (mode == PacketMode.StartSizeStopCompressSum)
     {
         return(CreatePacket_StartSizeStopCompressSum(data));
     }
     else
     {
         return(null);
     }
 }
예제 #5
0
파일: Utils.cs 프로젝트: pichiliani/CoMusic
        private void ProcessPacket(PacketMode mode, TransportPacket packet, DelayQueue<TransportPacket> queue)
        {
            uint delay = (uint)Math.Max(0, CalculateDelay());
            if (Ordering != Ordering.Unordered)
            {
                // if this transport is ordered or sequenced, then the packets
                // must be sent in order, and thus must be delayed in order.
                // Thus when figuring out the possible delay of a packet,
                // we must ensure it's at least as delayed as the previous
                // packet, which must be the most-delayed packet.
                delay = (uint)Math.Max(delay, lastPacketTime[mode] - timer.TimeInMilliseconds);
            }

            if (Reliability != Reliability.Reliable || Ordering != Ordering.Ordered)
            {
                double pDropped = PacketLossCorrelation * pLastDropped +
                    (1d - PacketLossCorrelation) * urng.NextDouble();
                pLastDropped = pDropped;
                if(pDropped < PacketLoss)
                {
                    NotifyPacketDisposition(mode, PacketEffect.Dropped, packet);
                    return;
                }
            }

            // don't include reordering time when recording the scheduled
            // time for this current packet -- if we reorder by delaying,
            // then we *don't* want subsequent packets
            lastPacketTime[mode] = timer.TimeInMilliseconds + delay;

            // Sequenced and ordered transports cannot have out-of-order packets
            if (Ordering == Ordering.Unordered && urng.NextDouble() < PacketReordering)
            {
                // reorder packets by delaying this current packet
                delay += queue.MaximumDelay == 0 ? 10u : queue.MaximumDelay / 2;
                NotifyPacketDisposition(mode, PacketEffect.Reordered, packet);
            }
            else if(delay > 0)
            {
                NotifyPacketDisposition(mode, PacketEffect.Delayed, packet);
            }
            else
            {
                NotifyPacketDisposition(mode, PacketEffect.None, packet);
            }
            packet.Retain();    // countered in Really{Send,Receive}Packet
            queue.Enqueue(packet, delay);
        }
예제 #6
0
파일: Utils.cs 프로젝트: pichiliani/CoMusic
 private void NotifyPacketDisposition(PacketMode mode, PacketEffect effect, TransportPacket packet)
 {
     if(PacketDisposition != null)
     {
         PacketDisposition(mode, effect, packet);
     }
 }
예제 #7
0
파일: IDSocket.cs 프로젝트: pb0/ID0_Test
        private ErrCode IssueRecvPacketData()
        {
            m_packetMode = PacketMode.Data;

            try
            {
                m_readByte = Read(m_recvPacketSize - GetRecvBufSize());
            }
            catch (Exception e)
            {
                HandleLog(string.Format("IDSocket.IssueRecvPacketData() Exception={0}", e.Message));
                return ErrCode.NetworkIoRead;
            }

            return ErrCode.Success;
        }