Exemplo n.º 1
0
 public TcpChannelTest()
 {
     LogManager.Assign(new SimpleLogManager <ConsoleLogger>());
     _pipeline = new MyPipeline();
     _sockets  = SocketTestTools.CreateConnection();
     _target   = new TcpServerChildChannel(_pipeline);
     _target.AssignSocket(_sockets.Client);
     _target.StartChannel();
 }
Exemplo n.º 2
0
        public void FillBuffers()
        {
            LogManager.Assign(new SimpleLogManager <ConsoleLogger>());

            var pool = new BufferPool(100, 2, 2);

            _target = new TcpServerChildChannel(_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.Position, 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);
                }
            }
        }
Exemplo n.º 3
0
 private void OnAcceptSocket(IAsyncResult ar)
 {
     try
     {
         if (_listener == null)
         {
             HandleException(new NullReferenceException());
             return;
         }
         Socket socket = _listener.EndAcceptSocket(ar);
         _listener.BeginAcceptSocket(OnAcceptSocket, null);
         _logger.Debug("Accepted client from " + socket.RemoteEndPoint);
         var client = new TcpServerChildChannel(_childPipelineFactory.Build(), _bufferPool);
         client.AssignSocket(socket);
         client.StartChannel();
         SendUpstream(new ChildChannelConnected(client));
     }
     catch (Exception err)
     {
         HandleException(err);
     }
 }