Ejemplo n.º 1
0
 /// <summary>
 /// TCP 服务器端同步调用任务处理
 /// </summary>
 protected override void run()
 {
     do
     {
         WaitHandle.Wait();
         QueueLock.EnterYield();
         ServerCallBase value = head;
         end  = null;
         head = null;
         QueueLock.Exit();
         do
         {
             try
             {
                 while (value != null)
                 {
                     current = null;
                     value.RunTask(ref value);
                 }
                 break;
             }
             catch (Exception error)
             {
                 log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
             }
         }while (true);
     }while (!isDisposed);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 消息队列读取操作任务处理
 /// </summary>
 protected override void run()
 {
     do
     {
         WaitHandle.Wait();
         QueueLock.EnterYield();
         T value = head;
         end  = null;
         head = null;
         QueueLock.Exit();
         do
         {
             try
             {
                 do
                 {
                     value.RunTask(ref value);
                 }while (value != null);
                 break;
             }
             catch (Exception error)
             {
                 AutoCSer.LogHelper.Exception(error);
             }
         }while (value != null);
     }while (true);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// TCP 服务器端同步调用任务处理
 /// </summary>
 protected override void run()
 {
     do
     {
         WaitHandle.Wait();
         QueueLock.EnterYield();
         Buffer value = head;
         end  = null;
         head = null;
         QueueLock.Exit();
         do
         {
             try
             {
                 while (value != null)
                 {
                     value.OnPacket(ref value, onPacket);
                 }
                 break;
             }
             catch (Exception error)
             {
                 log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
             }
         }while (true);
     }while (!isDisposed);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Flushs the update queue. Takes the list of all updates queued for the client and calls the client's callback, passing this list as parameter
        /// </summary>
        private void FlushUpdateQueue()
        {
            while (true)
            {
                bool gotLock = false;
                try
                {
                    QueueLock.Enter(ref gotLock);

                    if (UpdateQueue.Count > 0)
                    {
                        InvokeClientCallbacks();
                        UpdateQueue.Clear();
                    }
                }
                finally
                {
                    if (gotLock)
                    {
                        QueueLock.Exit();
                    }
                }

                // Wait for updates to accumulate (to send them in batches)
                Thread.Sleep(10);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// TCP 服务器端同步调用任务处理
 /// </summary>
 protected override void run()
 {
     do
     {
         WaitHandle.Wait();
         QueueLock.EnterYield();
         ClientCommand.CommandBase value = head;
         end  = null;
         head = null;
         QueueLock.Exit();
         do
         {
             try
             {
                 do
                 {
                     value.OnReceiveTask(ref value);
                 }while (value != null);
                 break;
             }
             catch (Exception error)
             {
                 AutoCSer.LogHelper.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
             }
         }while (value != null);
     }while (true);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 添加任务
 /// </summary>
 /// <param name="value"></param>
 internal void Add(T value)
 {
     QueueLock.EnterYield();
     if (head == null)
     {
         end  = value;
         head = value;
         QueueLock.Exit();
         WaitHandle.Set();
     }
     else
     {
         end.LinkNext = value;
         end          = value;
         QueueLock.Exit();
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 添加任务
 /// </summary>
 /// <param name="head"></param>
 /// <param name="end"></param>
 internal void Add(T head, T end)
 {
     QueueLock.EnterYield();
     if (this.head == null)
     {
         this.end  = end;
         this.head = head;
         QueueLock.Exit();
         WaitHandle.Set();
     }
     else
     {
         this.end.LinkNext = head;
         this.end          = end;
         QueueLock.Exit();
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds update information about an entity to the update queue after having received an attributeChanged event
        /// </summary>
        /// <param name="sender">Entity that invoked the attribute change event</param>
        /// <param name="e">Event Arguments</param>
        private void AddEntityUpdateToQueue(Object sender, ChangedAttributeEventArgs e)
        {
            bool gotLock = false;

            try
            {
                QueueLock.Enter(ref gotLock);
                UpdateQueue.Add(CreateUpdateInfoFromEventArgs((Entity)sender, e));
            }
            finally
            {
                if (gotLock)
                {
                    QueueLock.Exit();
                }
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 添加任务
 /// </summary>
 /// <param name="value"></param>
 internal void Add(ClientCommand.CommandBase value)
 {
     QueueLock.EnterYield();
     if (head == null)
     {
         end  = value;
         head = value;
         QueueLock.Exit();
         WaitHandle.Set();
     }
     else
     {
         end.NextTask = value;
         end          = value;
         QueueLock.Exit();
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 添加任务
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool CheckAdd(T value)
 {
     QueueLock.EnterYield();
     if (value.LinkNext == null && value != end)
     {
         if (head == null)
         {
             end  = value;
             head = value;
             QueueLock.Exit();
             WaitHandle.Set();
         }
         else
         {
             end.LinkNext = value;
             end          = value;
             QueueLock.Exit();
         }
         return(true);
     }
     QueueLock.Exit();
     return(false);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Removes all unsent update information of a removed entity from the update queue
        /// </summary>
        /// <param name="entityGuid">Guid of the removed entity/param>
        private void RemoveEntityFromQueue(Entity entity)
        {
            bool gotLock = false;

            try
            {
                QueueLock.Enter(ref gotLock);

                foreach (UpdateInfo entityUpdate in UpdateQueue)
                {
                    if (entityUpdate.entityGuid.Equals(entity.Guid))
                    {
                        UpdateQueue.Remove(entityUpdate);
                    }
                }
            }
            finally
            {
                if (gotLock)
                {
                    QueueLock.Exit();
                }
            }
        }