This class cannot be inherited.
Наследование: DisposableBase
Пример #1
0
        public void can_send_a_buffer()
        {
            using(var ctx = new TestContext())
            using(var session = new ProxySession(0, ctx.Output))
            {
                var expected = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

                session.SendAsync(new[] { expected });

                var actual = new byte[expected.Length];
                Assert.Equal(ctx.Input.Receive(actual), expected.Length);
                Assert.Equal(expected, actual);
                Assert.False(ctx.Input.Poll(PollTimeout, SelectMode.SelectRead));
            }
        }
Пример #2
0
        public void can_send_a_buffer_larger_than_the_internal_output_buffer()
        {
            using(var ctx = new TestContext())
            using(var session = new ProxySession(0, ctx.Output))
            {
                var expected = new byte[(int)(ProxySession.OutputBufferSize * 2.3)];
                for(int i = 0; i < expected.Length; ++i)
                {
                    expected[i] = (byte)i;
                }

                session.SendAsync(new[] { expected });

                int actualRead = 0;
                var actual = new byte[expected.Length];
                while(actualRead < actual.Length && ctx.Input.Poll(PollTimeout, SelectMode.SelectRead))
                {
                    actualRead += ctx.Input.Receive(actual, actualRead, actual.Length - actualRead, SocketFlags.None);
                }
                Assert.Equal(expected.Length, actualRead);
                Assert.Equal(expected, actual);
                Assert.False(ctx.Input.Poll(PollTimeout, SelectMode.SelectRead));
            }
        }
Пример #3
0
 public void send_throws_if_buffer_is_null()
 {
     using(var session = new ProxySession(123, CreateSocket()))
     {
         Assert.Throws<ArgumentNullException>(() => session.SendAsync(null));
     }
 }
Пример #4
0
 public void proxy_raises_disposed_event_once_when_disposed()
 {
     using(var client = CreateSocket())
     {
         int disposedCount = 0;
         var session = new ProxySession(1, client);
         session.Disposed += delegate { ++disposedCount; };
         ((IDisposable)session).Dispose();
         ((IDisposable)session).Dispose();
         Assert.Equal(1, disposedCount);
     }
 }
Пример #5
0
 public void proxy_disposes_of_client()
 {
     using(var client = CreateSocket())
     {
         var session = new ProxySession(1, client);
         ((IDisposable)session).Dispose();
         Assert.Throws<ObjectDisposedException>(() => client.Poll(PollTimeout, SelectMode.SelectRead));
     }
 }
Пример #6
0
 public void ctor_sets_id()
 {
     using(var session = new ProxySession(123, CreateSocket()))
     {
         Assert.Equal(123, session.Id);
     }
 }
Пример #7
0
        public void can_send_multiple_buffers()
        {
            using(var ctx = new TestContext())
            using(var session = new ProxySession(0, ctx.Output))
            {
                var buffers = new[] {
                    new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                    new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 },
                    new byte[] { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 },
                    new byte[] { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }
                };
                var expected = buffers.SelectMany(x => x).ToArray();

                session.SendAsync(buffers);

                var actual = new byte[expected.Length];
                Assert.Equal(ctx.Input.Receive(actual), expected.Length);
                Assert.Equal(expected, actual);
                Assert.False(ctx.Input.Poll(PollTimeout, SelectMode.SelectRead));
            }
        }
Пример #8
0
 private void AddPendingStart(Socket client)
 {
     var session = new ProxySession(NextSessionId(), client);
     session.Disposed += OnSessionDisposed;
     _sessionsPendingStart.Add(session);
     _wakeUpMainTask.Set();
 }