SendAsync() public method

Begins an asynchronous operation to send the specified buffer.
/// Thrown when the this instance has been disposed of. ///
public SendAsync ( ByteBufferSnapshot buffer ) : void
buffer AK.F1.Timing.Server.IO.ByteBufferSnapshot The buffer to send.
return void
コード例 #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 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));
            }
        }