Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #4
0
 public bool TryWaitForOutgoingPacket(int timeoutInSeconds, out NetworkInterfaceTesterResult result)
 {
     return(frames.TryTake(out result, timeoutInSeconds * 1000));
 }