Example #1
0
 /// <summary>
 /// 套接字处理
 /// </summary>
 internal new void OnSocket()
 {
     while (this.socket != null)
     {
         socketHandle.Wait();
         SocketLink socket = Interlocked.Exchange(ref socketHead, null);
         do
         {
             try
             {
                 while (socket != null)
                 {
                     socket = socket.Start(this);
                 }
                 break;
             }
             catch (Exception error)
             {
                 RegisterServer.TcpServer.Log.Add(AutoCSer.Log.LogType.Debug, error);
             }
             socket = socket.Cancel();
         }while (true);
     }
     socketHead = null;
 }
Example #2
0
 /// <summary>
 /// 套接字处理
 /// </summary>
 internal void OnSocket()
 {
     while (this.socket != null)
     {
         socketHandle.Wait();
         SocketLink socket = Interlocked.Exchange(ref socketHead, null);
         do
         {
             try
             {
                 while (socket != null)
                 {
                     socket = socket.Start(this);
                 }
                 break;
             }
             catch (Exception error)
             {
                 RegisterServer.TcpServer.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
             }
             socket = socket.Cancel();
         }while (true);
     }
     socketHead = null;
 }
Example #3
0
        /// <summary>
        /// 获取客户端请求
        /// </summary>
        private void getSocket()
        {
            System.Net.Sockets.Socket listenSocket = socket;
            SocketLink newSocketLink, head;

            while (socket != null)
            {
                try
                {
NEXT:
                    newSocketLink        = new SocketLink();
                    newSocketLink.Socket = listenSocket.Accept();
                    if (socket == null)
                    {
                        return;
                    }
                    do
                    {
                        if ((head = socketHead) == null)
                        {
                            newSocketLink.LinkNext = null;
                            if (Interlocked.CompareExchange(ref socketHead, newSocketLink, null) == null)
                            {
                                socketHandle.Set();
                                newSocketLink = null;
                                goto NEXT;
                            }
                        }
                        else
                        {
                            newSocketLink.LinkNext = head;
                            if (Interlocked.CompareExchange(ref socketHead, newSocketLink, head) == head)
                            {
                                newSocketLink = null;
                                goto NEXT;
                            }
                        }
                        AutoCSer.Threading.ThreadYield.YieldOnly();
                    }while (true);
                }
                catch (Exception error)
                {
                    if (socket == null)
                    {
                        break;
                    }
                    RegisterServer.TcpServer.Log.Add(AutoCSer.Log.LogType.Error, error);
                    Thread.Sleep(1);
                }
            }
        }