Exemple #1
0
        public void can_write_given_a_source_offset()
        {
            BufferPool pool = new BufferPool(1, BufferManager);

            byte[] data = { 1, 2, 3, 4, 5 };
            pool.Write(0, data, 3, 2);
            Assert.AreEqual(pool[0], 4);
            Assert.AreEqual(pool[1], 5);
        }
Exemple #2
0
        public bool EnsureSend(byte[] data)
        {
            try
            {
                TaskQueuePool.CheckError();

                if (!BufferPool.Write(data))
                {
                    return(false);
                }

                if (TaskQueuePool.ActionQueue.Count > 1 && TaskQueuePool.RunTask.Status == System.Threading.Tasks.TaskStatus.Running)
                {
                    return(true);
                }

                TaskQueuePool.Push(new ActionRun <Socket>((sock) =>
                {
                    if (BufferPool.Length == 0)
                    {
                        return(true);
                    }

                    while (BufferPool.Length > 0)
                    {
                        int lengt = BufferPool.Length;

                        byte[] pdata = BufferPool.ReadNoPostion(lengt);

                        int sendlengt = sock.Send(pdata, 0, pdata.Length, SocketFlags.None);

                        BufferPool.SubLength(sendlengt);
                    }

                    if (BufferPool.Length == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }, Asyn.AcceptSocket));

                return(true);
            }
            catch (Exception er)
            {
                ActionRun <Socket> actionRun;
                for (int i = 0; i < TaskQueuePool.ActionQueue.Count; i++)
                {
                    TaskQueuePool.ActionQueue.TryDequeue(out actionRun);
                }

                throw er;
            }
        }
Exemple #3
0
        public void Test6()
        {
            BufferPool bufferPool = new BufferPool();

            byte[] writeBytes = new byte[_capacity];
            Array.Clear(writeBytes, 0, writeBytes.Length);
            bufferPool.Write(writeBytes, 0, writeBytes.Length);
            bufferPool.Seek(-1);
        }
Exemple #4
0
        public void can_write_given_a_self_offset()
        {
            BufferPool pool = new BufferPool(1, BufferManager);

            byte[] data = { 1, 2, 3, 4, 5 };
            pool.Write(4, data, 0, 5); //start at position 4
            for (byte i = 4; i < 9; i++)
            {
                Assert.AreEqual(i - 3, pool[i]);
            }
        }
Exemple #5
0
        public void Test2()
        {
            BufferPool bufferPool = new BufferPool();

            byte[] writeBytes = new byte[_capacity];
            for (int i = 0; i < writeBytes.Length; i++)
            {
                writeBytes[i] = (byte)i;
            }
            bufferPool.Write(writeBytes, 0, writeBytes.Length);
            byte[] readBytes = new byte[(_capacity >> 1)];
            bufferPool.Read(readBytes, 0, readBytes.Length);
            for (int i = 0; i < readBytes.Length; i++)
            {
                Assert.AreEqual(writeBytes[i], readBytes[i]);
            }
        }
 public void can_write_given_a_source_offset()
 {
     BufferPool pool = new BufferPool(1, BufferManager);
     byte[] data = { 1, 2, 3, 4, 5 };
     pool.Write(0, data, 3, 2);
     Assert.AreEqual(pool[0], 4);
     Assert.AreEqual(pool[1], 5);
 }
 public void can_write_given_a_self_offset()
 {
     BufferPool pool = new BufferPool(1, BufferManager);
     byte[] data = { 1, 2, 3, 4, 5 };
     pool.Write(4, data, 0, 5); //start at position 4
     for (byte i = 4; i < 9; i++)
     {
         Assert.AreEqual(i - 3, pool[i]);
     }
 }
 public void a_negative_offset_throws_an_argumentoutofrangeexception()
 {
     BufferPool pool = new BufferPool(1, BufferManager);
     pool.Write(0, new byte[5], -1, 1);
 }
 public void a_count_larger_than_the_buffer_throws_an_argumentoutofrangeexception()
 {
     BufferPool pool = new BufferPool(1, BufferManager);
     pool.Write(0, new byte[5], 3, 5);
 }
Exemple #10
0
        public void a_negative_offset_throws_an_argumentoutofrangeexception()
        {
            BufferPool pool = new BufferPool(1, BufferManager);

            Assert.Throws <ArgumentOutOfRangeException>(() => { pool.Write(0, new byte[5], -1, 1); });
        }
Exemple #11
0
        public void a_count_larger_than_the_buffer_throws_an_argumentoutofrangeexception()
        {
            BufferPool pool = new BufferPool(1, BufferManager);

            Assert.Throws <ArgumentOutOfRangeException>(() => { pool.Write(0, new byte[5], 3, 5); });
        }
Exemple #12
0
        public void a_negative_offset_throws_an_argumentoutofrangeexception()
        {
            BufferPool pool = new BufferPool(1, BufferManager);

            pool.Write(0, new byte[5], -1, 1);
        }
Exemple #13
0
        public void a_count_larger_than_the_buffer_throws_an_argumentoutofrangeexception()
        {
            BufferPool pool = new BufferPool(1, BufferManager);

            pool.Write(0, new byte[5], 3, 5);
        }