Пример #1
0
        private void ProcessWork(Loop loop, IAsyncWatcher watcher, EventTypes revents)
        {
            int remaining = maxWorkPerLoop + 1;

            while (--remaining > 0)
            {
                Action action;
                if (workQueue.TryDequeue(out action))
                {
                    try {
                        action();
                    }
                    catch (Exception ex) {
                        Console.WriteLine("Error in processing synchronized action");
                        Console.WriteLine(ex);
                    }
                }
                else
                {
                    break;
                }
            }

            if (remaining == 0)
            {
                asyncWatcher.Send();
            }
        }
Пример #2
0
 internal virtual void HandleEnd(Loop loop, IAsyncWatcher watcher, EventTypes revents)
 {
     if (OnEnd != null)
     {
         OnEnd();
     }
 }
Пример #3
0
        public Boundary(Context context, int maxWorkPerLoop)
        {
            asyncWatcher = context.CreateAsyncWatcher(ProcessWork);
            asyncWatcher.Start();

            workQueue = new ConcurrentQueue<Action>();
            this.maxWorkPerLoop = maxWorkPerLoop;
        }
Пример #4
0
        public Boundary(Context context, int maxWorkPerLoop)
        {
            asyncWatcher = context.CreateAsyncWatcher(ProcessWork);
            asyncWatcher.Start();

            workQueue           = new ConcurrentQueue <Action> ();
            this.maxWorkPerLoop = maxWorkPerLoop;
        }
Пример #5
0
        public Boundary(IOLoop loop, int maxWorkPerLoop)
        {
            asyncWatcher = loop.NewAsyncWatcher(ProcessWork);
            asyncWatcher.Start();

            workQueue           = new ConcurrentQueue <Action> ();
            this.maxWorkPerLoop = maxWorkPerLoop;
        }
Пример #6
0
 public void Complete(Action callback)
 {
     completeWatcher = IOLoop.Instance.NewAsyncWatcher(delegate {
         completeWatcher.Dispose();
         completeWatcher = null;
         callback();
     });
     completeWatcher.Start();
     Stream.End(completeWatcher.Send);
 }
Пример #7
0
        public void Complete(Action callback)
        {
            IAsyncWatcher completeWatcher = null;

            completeWatcher = Context.CreateAsyncWatcher(delegate {
                completeWatcher.Dispose();
                callback();
            });
            completeWatcher.Start();
            Stream.End(completeWatcher.Send);
        }
Пример #8
0
 public AsyncWatcher(Context context, Action <T> callback)
 {
     asyncWatcher = context.CreateAsyncWatcher(() => {
         T item;
         lock (queue) {
             item = queue.Dequeue();
         }
         if (callback != null)
         {
             callback(item);
         }
     });
 }
Пример #9
0
        public void Dispose()
        {
            Socket = null;

            if (Stream != null)
            {
                Stream.Dispose();
                Stream = null;
            }

            if (end_watcher != null)
            {
                end_watcher.Dispose();
                end_watcher = null;
            }
        }
Пример #10
0
 public HttpEntity()
 {
     end_watcher = IOLoop.Instance.NewAsyncWatcher(HandleEnd);
     end_watcher.Start();
 }
Пример #11
0
 public HttpEntity(Context context)
 {
     this.Context = context;
     end_watcher  = context.CreateAsyncWatcher(HandleEnd);
     end_watcher.Start();
 }