Пример #1
0
 /// <summary>
 /// 获取域名服务信息
 /// </summary>
 /// <param name="domain">域名</param>
 /// <param name="size">域名长度</param>
 /// <returns>域名服务信息</returns>
 internal DomainServer Get(byte *domain, int size)
 {
     if (searcher.State != null)
     {
         if (lastDomainSize == size && lastLock.TryEnter())
         {
             if (lastDomainSize == size && AutoCSer.Memory.Common.SimpleEqualNotNull(lastDomain.Byte, domain, lastDomainSize))
             {
                 DomainServer server = lastServer;
                 lastLock.Exit();
                 return(server);
             }
             lastLock.Exit();
         }
         int index = searcher.Search(domain, domain + size);
         if (index >= 0)
         {
             DomainServer server = servers[index];
             if (server != null)
             {
                 if (lastLock.TryEnter())
                 {
                     if (lastDomain.Byte == null)
                     {
                         lastLock.SleepFlag = 1;
                         try
                         {
                             lastDomain = Unmanaged.GetPointer(Server.MaxDomainSize, false);
                             AutoCSer.Memory.Common.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                             lastServer = server;
                         }
                         finally { lastLock.ExitSleepFlag(); }
                     }
                     else
                     {
                         AutoCSer.Memory.Common.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                         lastServer = server;
                         lastLock.Exit();
                     }
                 }
                 return(server);
             }
         }
     }
     return(null);
 }
Пример #2
0
 /// <summary>
 /// 获取域名服务信息
 /// </summary>
 /// <param name="domain">域名</param>
 /// <param name="size">域名长度</param>
 /// <returns>域名服务信息</returns>
 internal DomainServer Get(byte *domain, int size)
 {
     if (searcher.State != null)
     {
         if (lastDomainSize == size && Monitor.TryEnter(lastLock))
         {
             if (lastDomainSize == size && Memory.SimpleEqualNotNull(lastDomain.Byte, domain, lastDomainSize))
             {
                 DomainServer server = lastServer;
                 Monitor.Exit(lastLock);
                 return(server);
             }
             Monitor.Exit(lastLock);
         }
         int index = searcher.Search(domain, domain + size);
         if (index >= 0)
         {
             DomainServer server = servers[index];
             if (server != null)
             {
                 if (Monitor.TryEnter(lastLock))
                 {
                     if (lastDomain.Byte == null)
                     {
                         try
                         {
                             lastDomain = Unmanaged.Get(Server.MaxDomainSize, false, false);
                             Memory.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                             lastServer = server;
                         }
                         finally { Monitor.Exit(lastLock); }
                     }
                     else
                     {
                         Memory.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                         lastServer = server;
                         Monitor.Exit(lastLock);
                     }
                 }
                 return(server);
             }
         }
     }
     return(null);
 }