Пример #1
0
        static void Write()
        {
            using (var stream = new FileStream("test_32", FileMode.Create, FileAccess.ReadWrite, FileShare.Read, Constants.BlockSize /* , FileOptions.DeleteOnClose */))
            {
                var writer = new BlockWriter(stream);

                long seq = 0;

                for (int i = 800; i < 1000; i++)
                {
                    for (int n = 0; n < 1000; n++)
                    {
                        var packet = new Packet()
                        {
                            Flow           = TrafficFlow.Inbound,
                            Source         = new IPEndPoint(IPAddress.Loopback, 123),
                            Destination    = new IPEndPoint(IPAddress.Loopback, 456),
                            SequenceNumber = seq++,
                            Payload        = CreatePayload(i * 1),
                        };

                        writer.Write(packet);
                    }
                }
            }
        }
Пример #2
0
        static void WriteSmall()
        {
            using (var stream = new FileStream("test_s", FileMode.Create, FileAccess.ReadWrite, FileShare.Read, Constants.BlockSize /* , FileOptions.DeleteOnClose */))
            {
                var writer = new BlockWriter(stream);

                long seq = 0;

                for (int i = 800; i < 850; i++)
                {
                    for (int c = 0; c < 1; c++)
                    {
                        var packet = new Packet()
                        {
                            Flow           = i % 2 == 0 ? TrafficFlow.Inbound : TrafficFlow.Outbound,
                            Source         = new IPEndPoint(IPAddress.Loopback, 123),
                            Destination    = new IPEndPoint(IPAddress.Loopback, 456),
                            SequenceNumber = seq++,
                            Payload        = new byte[i],
                        };

                        var data = packet.Payload;

                        for (int n = 0; n < data.Length; n++)
                        {
                            data[n] = (byte)((n + 32) % 192);
                        }

                        writer.Write(packet);
                    }
                }
            }
        }
Пример #3
0
        private void Open()
        {
            var options = FileOptions.None;

            if (DeleteOnClose)
            {
                options |= FileOptions.DeleteOnClose;
            }

            if (CanWrite)
            {
                if (LowestAllowedOffset != 0 || HighestAllowedOffset != 0)
                {
                    throw new InvalidOperationException($"{nameof(LowestAllowedOffset)} and {nameof(HighestAllowedOffset)} must be zero.");
                }

                writerStream = new FileStream(FileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read | FileShare.Delete, Constants.BlockSize, options);
                writer       = new BlockWriter(writerStream);
            }

            readerStream = OpenRead();

            if (HighestAllowedOffset == 0)
            {
                HighestAllowedOffset = readerStream.Length;
            }

            reader = new BlockReader(readerStream)
            {
                HighestAllowedOffset = HighestAllowedOffset
            };

            BlockIterator = new CachedBlockIterator(reader);

            FileLength = HighestAllowedOffset;
        }