Exemplo n.º 1
0
        public bool EnsureSend(byte[] data)
        {
            try
            {
                TaskQueuePool.CheckError();

                if (!BufferPool.Write(data))
                {
                    return(false);
                }

                if (TaskQueuePool.ActionQueue.Count > 1 && TaskQueuePool.RunTask.Status == System.Threading.Tasks.TaskStatus.Running)
                {
                    return(true);
                }

                TaskQueuePool.Push(new ActionRun <Socket>((sock) =>
                {
                    if (BufferPool.Length == 0)
                    {
                        return(true);
                    }

                    while (BufferPool.Length > 0)
                    {
                        int lengt = BufferPool.Length;

                        byte[] pdata = BufferPool.ReadNoPostion(lengt);

                        int sendlengt = sock.Send(pdata, 0, pdata.Length, SocketFlags.None);

                        BufferPool.SubLength(sendlengt);
                    }

                    if (BufferPool.Length == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }, Asyn.AcceptSocket));

                return(true);
            }
            catch (Exception er)
            {
                ActionRun <Socket> actionRun;
                for (int i = 0; i < TaskQueuePool.ActionQueue.Count; i++)
                {
                    TaskQueuePool.ActionQueue.TryDequeue(out actionRun);
                }

                throw er;
            }
        }
Exemplo n.º 2
0
        static FeedJob()
        {
            basePath     = AppDomain.CurrentDomain.BaseDirectory;
            snapshotPath = Path.Combine(basePath, "snapshot");
            delayPath    = Path.Combine(basePath + "delay");

            queuePool = new TaskQueuePool(8);
            queuePool.Start();
        }
Exemplo n.º 3
0
        public void TestMethod1()
        {
            var pool = new TaskQueuePool(4);

            pool.Start();

            pool.QueueAction((f) => {
                Thread.Sleep(100);

                Debug.Write(" first");
                Debug.Write(" queue count : " + pool.Count);
                Debug.WriteLine(" current tasks : " + pool.CurrentTasks);
            }, "first");

            Thread.Sleep(1000);

            for (int i = 0; i < 10; i++)
            {
                pool.QueueAction((index) => {
                    Thread.Sleep(1000);

                    Debug.WriteLine("aaaa " + index + " queue count : " + pool.Count + " current tasks : " + pool.CurrentTasks);
                }, i);
            }

            for (int i = 10; i < 20; i++)
            {
                pool.QueueAction((index) => {
                    Thread.Sleep(2000);

                    Debug.WriteLine("bbbb " + index + " queue count : " + pool.Count + " current tasks : " + pool.CurrentTasks);
                }, i);
            }

            Thread.Sleep(10000);

            for (int i = 20; i < 50; i++)
            {
                pool.QueueAction((index) => {
                    Thread.Sleep(500);

                    Debug.WriteLine("cccc " + index + " queue count : " + pool.Count + " current tasks : " + pool.CurrentTasks);
                }, i);
            }

            Thread.Sleep(1000000);
            Assert.True(true);
        }
Exemplo n.º 4
0
        static FeedExtractJob()
        {
            basePath     = AppDomain.CurrentDomain.BaseDirectory;
            snapshotPath = Path.Combine(basePath, "snapshot");
            failPath     = Path.Combine(basePath, "save_failed");
            historyPath  = Path.Combine(basePath + "history");
            delayPath    = Path.Combine(basePath + "delay");

            Directory.CreateDirectory(snapshotPath);
            Directory.CreateDirectory(failPath);
            Directory.CreateDirectory(historyPath);
            Directory.CreateDirectory(delayPath);
            Directory.CreateDirectory(Path.Combine(basePath + "pre"));

            if (Environment.ProcessorCount == 1)
            {
                queuePool = FeedJob.queuePool;
            }
            else
            {
                queuePool = new TaskQueuePool(8);
                queuePool.Start();
            }
        }