public TcpChannelTest() { _pipeline = new MyPipeline(); _sockets = SocketTestTools.CreateConnection(); _target = new TcpServerClientChannel(_pipeline); _target.AssignSocket(_sockets.Client); _target.StartChannel(); }
public void FillBuffers() { LogManager.Assign(new SimpleSystemDebugLogManager()); var pool = new BufferPool(100, 2, 2); _target = new TcpServerClientChannel(_pipeline, pool); _target.AssignSocket(_sockets.Client); _target.StartChannel(); var sb = new StringBuilder(); for (int i = 0; i < 1000; i++) { sb.Append(i.ToString()); sb.Append("|"); if ((i % 25) == 0) sb.AppendLine(); } var sendBuffer = Encoding.ASCII.GetBytes(sb.ToString()); var sent = 0; while (sent < sendBuffer.Length) { sent += _sockets.Server.Send(sendBuffer, sent, sendBuffer.Length - sent, SocketFlags.None); } Assert.True(_pipeline.WaitOnUpstream<Received>(TimeSpan.FromMilliseconds(1000)), "Incoming message timeout"); var receivedBuffer = new byte[sendBuffer.Length]; var stream= new MemoryStream(receivedBuffer); foreach (var msg in _pipeline.UpstreamMessages) { var m = msg as Received; if (m == null) continue; stream.Write(m.BufferSlice.Buffer, m.BufferSlice.CurrentOffset, m.BufferSlice.RemainingLength); } stream.Flush(); Assert.Equal(sendBuffer.Length, receivedBuffer.Length); for (int i = 0; i < sendBuffer.Length; i++) { if (sendBuffer[i] != receivedBuffer[i]) throw new InvalidOperationException("First difference at " + i); } }