Exemplo n.º 1
0
 /// <summary>
 /// 定时器触发
 /// </summary>
 private void onTimer()
 {
     do
     {
         try
         {
             do
             {
                 while (System.Threading.Interlocked.CompareExchange(ref queueLock, 1, 0) != 0)
                 {
                     AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.TimerLinkQueuePop);
                 }
                 Socket socket = null;
                 if (Head == null || Head.timeoutSeconds > currentSeconds)
                 {
                     System.Threading.Interlocked.Exchange(ref queueLock, 0);
                     return;
                 }
                 SocketTimeoutLink value = Head;
                 if (Head.getTimeoutSocket(ref socket) == 0)
                 {
                     if ((Head = Head.nextTimeout) == null)
                     {
                         End = null;
                         System.Threading.Interlocked.Exchange(ref queueLock, 0);
                     }
                     else
                     {
                         value.nextTimeout    = null;
                         Head.previousTimeout = null;
                         System.Threading.Interlocked.Exchange(ref queueLock, 0);
                     }
                     value.TimeoutDisposeSocket(socket);
                 }
                 else
                 {
                     value.timeoutSeconds = currentSeconds + seconds;
                     if ((Head = Head.nextTimeout) == null)
                     {
                         Head = value;
                         System.Threading.Interlocked.Exchange(ref queueLock, 0);
                     }
                     else
                     {
                         value.previousTimeout = End;
                         End.nextTimeout       = value;
                         value.nextTimeout     = null;
                         Head.previousTimeout  = null;
                         End = value;
                         System.Threading.Interlocked.Exchange(ref queueLock, 0);
                     }
                 }
             }while (true);
         }
         catch
         {
             AutoCSer.Log.CatchCount.Add(AutoCSer.Log.CatchCount.Type.SocketTimeoutLink_Dispose);
         }
     }while (true);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 弹出节点
 /// </summary>
 /// <param name="value"></param>
 internal void Cancel(SocketTimeoutLink value)
 {
     value.waitCancelTimeout();
     while (System.Threading.Interlocked.CompareExchange(ref queueLock, 1, 0) != 0)
     {
         AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.TimerLinkQueuePop);
     }
     if (value == End)
     {
         if ((End = value.previousTimeout) == null)
         {
             Head = null;
             System.Threading.Interlocked.Exchange(ref queueLock, 0);
         }
         else
         {
             End.nextTimeout = value.previousTimeout = null;
             System.Threading.Interlocked.Exchange(ref queueLock, 0);
         }
     }
     else if (value == Head)
     {
         Head = value.nextTimeout;
         Head.previousTimeout = value.nextTimeout = null;
         System.Threading.Interlocked.Exchange(ref queueLock, 0);
     }
     else
     {
         value.freeTimeout();
         System.Threading.Interlocked.Exchange(ref queueLock, 0);
     }
 }
Exemplo n.º 3
0
 internal static void Free(ref SocketTimeoutLink timeout)
 {
     if (timeout != null)
     {
         AutoCSer.Threading.SecondTimer.InternalTaskArray.NodeLink.PopNotNull(timeout);
         timeout = null;
     }
 }
Exemplo n.º 4
0
 private void freeTimeout()
 {
     if (nextTimeout != null)
     {
         previousTimeout.nextTimeout = nextTimeout;
         nextTimeout.previousTimeout = previousTimeout;
         previousTimeout             = nextTimeout = null;
     }
 }
Exemplo n.º 5
0
            internal void OnTimer()
            {
                ++currentSeconds;
                SocketTimeoutLink head = Head;

                if (head != null && head.timeoutSeconds <= currentSeconds && Interlocked.CompareExchange(ref isTimer, 1, 0) == 0)
                {
                    onTimer();
                    System.Threading.Interlocked.Exchange(ref isTimer, 0);
                }
            }
Exemplo n.º 6
0
 ///// <summary>
 ///// 添加超时套接字
 ///// </summary>
 ///// <param name="value"></param>
 //[MethodImpl(AutoCSer.MethodImpl.AggressiveInlining)]
 //internal void Push(SocketTimeoutLink value)
 //{
 //    value.setTimeout(currentSeconds + seconds);
 //    push(value);
 //}
 /// <summary>
 /// 添加超时套接字
 /// </summary>
 /// <param name="value"></param>
 /// <param name="socket"></param>
 /// <param name="count"></param>
 internal void Push(SocketTimeoutLink value, Socket socket, ushort count = 0)
 {
     value.setTimeout(currentSeconds + seconds, socket, count);
     while (System.Threading.Interlocked.CompareExchange(ref queueLock, 1, 0) != 0)
     {
         AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.TimerLinkQueuePush);
     }
     if (End == null)
     {
         End = Head = value;
         System.Threading.Interlocked.Exchange(ref queueLock, 0);
     }
     else
     {
         End.nextTimeout       = value;
         value.previousTimeout = End;
         End = value;
         System.Threading.Interlocked.Exchange(ref queueLock, 0);
     }
     value.isSetReceiveTimeout = 1;
 }