Пример #1
0
        static void Main(string[] args)
        {
            pipeLineDeph = int.Parse(args.FirstOrDefault(f => f.StartsWith("-p"))?.Substring(2) ?? "16");
            int connections = int.Parse(args.FirstOrDefault(f => f.StartsWith("-c"))?.Substring(2) ?? "1024");

            Console.WriteLine("RioSharp http server");
            Console.WriteLine("Optimizing for " + connections + " connections");
            Console.WriteLine("Optimizing for pipeline depth of: " + pipeLineDeph);

            sendPool   = new RioFixedBufferPool(10 * connections, 256 * pipeLineDeph);
            recivePool = new RioFixedBufferPool(10 * connections, 256 * pipeLineDeph);

            listener       = new RioTcpListener(sendPool, recivePool, (uint)connections);
            currentSegment = listener.PreAllocateWrite(GetResponse());
            responseBytes  = GetResponse();
            //Task.Run(async () =>
            //{
            //    while (true)
            //    {
            //        UpdateResponse();
            //        await Task.Delay(60000);
            //    }
            //});

            listener.OnAccepted = new Action <RioSocket>(s => ThreadPool.QueueUserWorkItem(o => Servebuff((RioSocket)o), s));
            listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024 * connections);
            Console.WriteLine("Listening on : http://localhost:5000");
            Console.WriteLine("Press enter to exit");
            Console.ReadLine();

            listener.Dispose();
        }
Пример #2
0
        public static void ListenTcp()
        {
            RioTcpListener l = new RioTcpListener(new RioFixedBufferPool(16000, 65536), new RioFixedBufferPool(16000, 65536), (uint)Connections * 2, 16000, 16000);

            l.OnAccepted = s =>
            {
                RioStream r              = new RioStream(s);
                int       totalRecived   = 0;
                int       currentRecived = 0;
                var       reader         = new RioSegmentReader(s);

                var pb = new byte[PullBytes];
                if (Pattern == "PushPull")
                {
                    reader.OnIncommingSegment = seg =>
                    {
                        totalRecived   += seg.CurrentContentLength;
                        currentRecived += seg.CurrentContentLength;
                        if (currentRecived >= PushBytes)
                        {
                            r.Write(pb, 0, pb.Length);
                            //s.WriteFixed(pb);
                            currentRecived = 0;
                        }
                    };
                    reader.Start();
                }
                else if (Pattern == "Pull")
                {
                    r.Write(new byte[Transfer], 0, Transfer);
                }
                //s.WriteFixed(new byte[Transfer]);
                else if (Pattern == "Push")
                {
                    reader.OnIncommingSegment = seg =>
                    {
                        totalRecived += seg.CurrentContentLength;
                    };
                    reader.Start();
                }
                else if (Pattern == "Duplex")
                {
                    s.Send(new byte[Transfer / 2]);
                    reader.OnIncommingSegment = seg =>
                    {
                        totalRecived += seg.CurrentContentLength;
                        //if (apa >= Transfer / 2)
                        //    tcs.SetResult(null);
                    };
                }
            };
            l.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), Port), 1024);
        }
Пример #3
0
        public void Start <TContext>(IHttpApplication <TContext> application)
        {
            var information = Features.Get <IRioSharpServerInformation>();

            sendPool   = new RioFixedBufferPool(1000, 140 * information.PipeLineDepth);
            recivePool = new RioFixedBufferPool(1000, 64 * information.PipeLineDepth);
            listener   = new RioTcpListener(sendPool, recivePool, 1024);

            listener.OnAccepted = new Action <RioSocket>(s => ThreadPool.QueueUserWorkItem(o => Servebuff((RioSocket)o), s));
            listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024 * information.Connections);
            // do things
        }
Пример #4
0
        static void Main(string[] args)
        {
            clientPool = new RioTcpClientPool(new RioFixedBufferPool(100, 100), new RioFixedBufferPool(10, 100), 4096);
            listener   = new RioTcpListener(new RioFixedBufferPool(100, 100), new RioFixedBufferPool(100, 100), 4096);
            listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024);
            e = new ManualResetEvent(false);

            var task = Task.Run((Action)clientDisconnect);

            Log();
            Console.ReadLine();
            running = false;
            task.Wait();
            clientPool.Dispose();
            listener.Dispose();
        }