Ejemplo n.º 1
0
        public bool TryWaitForOutgoingPacketWithBytesAtIndex(string bytes, int index, int maxPackets, float timeout, out NetworkInterfaceTesterResult result)
        {
            if (bytes.Length % 2 != 0)
            {
                throw new ArgumentException("Partial bytes specified in the search pattern.");
            }

            int packetsChecked = 0;

            var machine      = iface.GetMachine();
            var timeoutEvent = machine.LocalTimeSource.EnqueueTimeoutEvent((ulong)(1000 * timeout));

            do
            {
                if (packetsChecked < maxPackets && frames.TryTake(out var frame))
                {
                    packetsChecked++;
                    if (IsMatch(bytes, index, frame.bytes))
                    {
                        result = frame;
                        return(true);
                    }
                }

                WaitHandle.WaitAny(new [] { timeoutEvent.WaitHandle, newFrameEvent });
            }while(!timeoutEvent.IsTriggered && packetsChecked < maxPackets);

            result = new NetworkInterfaceTesterResult();
            return(false);
        }
Ejemplo n.º 2
0
        public bool TryWaitForOutgoingPacket(float timeout, out NetworkInterfaceTesterResult result)
        {
            var machine      = iface.GetMachine();
            var timeoutEvent = machine.LocalTimeSource.EnqueueTimeoutEvent((ulong)(1000 * timeout));

            do
            {
                if (frames.TryTake(out result))
                {
                    return(true);
                }

                WaitHandle.WaitAny(new [] { timeoutEvent.WaitHandle, newFrameEvent });
            }while(!timeoutEvent.IsTriggered);

            result = default(NetworkInterfaceTesterResult);
            return(false);
        }
Ejemplo n.º 3
0
        public bool TryWaitForOutgoingPacketWithBytesAtIndex(string bytes, int index, int maxPackets, int singleTimeout, out NetworkInterfaceTesterResult result)
        {
            int packetsChecked = 0;

            if (bytes.Length % 2 != 0)
            {
                throw new ArgumentException("Partial bytes specified in the search pattern.");
            }

            while (packetsChecked++ < maxPackets)
            {
                if (!TryWaitForOutgoingPacket(singleTimeout, out var currentPacket))
                {
                    break;
                }

                if (index + (bytes.Length / 2) > currentPacket.bytes.Length)
                {
                    continue;
                }

                var matches = true;

                for (uint i = 0; i < bytes.Length; i += 2)
                {
                    var currentByte = currentPacket.bytes[index + (i / 2)];

                    if (!IsByteEqual(bytes, i, currentByte))
                    {
                        matches = false;
                        break;
                    }
                }

                if (matches)
                {
                    result = currentPacket;
                    return(true);
                }
            }

            result = new NetworkInterfaceTesterResult();
            return(false);
        }
Ejemplo n.º 4
0
 public bool TryWaitForOutgoingPacket(int timeoutInSeconds, out NetworkInterfaceTesterResult result)
 {
     return(frames.TryTake(out result, timeoutInSeconds * 1000));
 }