Exemplo n.º 1
0
        private FileCache get(ref FileCacheKey path)
        {
            Monitor.Enter(fileLock);
            FileCache file = files.Get(ref path, null);

            Monitor.Exit(fileLock);
            return(file);
        }
Exemplo n.º 2
0
        private FileCache get(ref FileCacheKey path)
        {
            fileLock.Enter();
            FileCache file = files.Get(ref path, null);

            fileLock.Exit();
            return(file);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据域名获取IP地址
        /// </summary>
        /// <param name="domain">域名</param>
        /// <returns>IP地址,失败返回null</returns>
        internal unsafe static                                                 IPAddress[] Get(ref SubArray <byte> domain)
        {
            try
            {
                fixed(byte *domainFixed = domain.Array)
                {
                    byte *domainStart = domainFixed + domain.StartIndex;

                    AutoCSer.Memory.ToLowerNotNull(domainStart, domainStart + domain.Length);
                    HashBytes       key = domain;
                    DomainIPAddress value;

                    Monitor.Enter(domainIpLock);
                    try
                    {
                        value = domainIps.Get(ref key, default(DomainIPAddress));
                        if (value.Ips != null && value.Timeout < AutoCSer.Date.NowTime.Now)
                        {
                            domainIps.Remove(ref key, out value);
                            value.Ips = null;
                        }
                    }
                    finally { Monitor.Exit(domainIpLock); }
                    if (value.Ips == null)
                    {
                        if (value.Domain == null)
                        {
                            value.Domain = Memory_WebClient.BytesToStringNotEmpty(domainStart, domain.Length);
                        }
                        IPAddress ip;
                        if (IPAddress.TryParse(value.Domain, out ip))
                        {
                            value.Timeout = DateTime.MaxValue;
                            value.Domain  = null;
                            setDomainIp(key.Copy(), ref value);
                            return(value.Ips = new IPAddress[] { ip });
                        }
                        value.Ips = Dns.GetHostEntry(value.Domain).AddressList;
                        if (value.Ips.Length != 0)
                        {
                            value.Timeout = AutoCSer.Date.NowTime.Now.AddTicks(domainIpTimeoutTicks);
                            setDomainIp(key.Copy(), ref value);
                            return(value.Ips);
                        }
                    }
                    else
                    {
                        return(value.Ips);
                    }
                }
            }
            catch (Exception error)
            {
                AutoCSer.Log.Pub.Log.add(AutoCSer.Log.LogType.Error, error);
            }
            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 日志写入
        /// </summary>
        private void output()
        {
            DebugInfo        value = null;
            FileStreamWriter fileStream;

            do
            {
                while (System.Threading.Interlocked.CompareExchange(ref debugLock, 1, 0) != 0)
                {
                    AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.FileLogExchangeDebug);
                }
                if (newDebugs.IsEmpty)
                {
                    System.Threading.Interlocked.Exchange(ref debugLock, 0);
                    return;
                }
                debugs.Exchange(ref newDebugs);
                System.Threading.Interlocked.Exchange(ref debugLock, 0);
                do
                {
                    try
                    {
                        while ((value = debugs.PopOnly()) != null)
                        {
                            switch (value.CacheType)
                            {
                            case CacheType.Queue:
                                HashString cacheKey = value.ToString();
                                if (cache.Get(ref cacheKey, false))
                                {
                                    fileStream = null;
                                }
                                else
                                {
                                    cache.UnsafeAdd(ref cacheKey, true);
                                    if (cache.Count > maxCacheCount)
                                    {
                                        cache.UnsafePopNode();
                                    }
                                    fileStream = this.fileStream;
                                }
                                break;

                            case CacheType.Last:
                                HashString key = value.ToString();
                                if (key.Equals(ref lastCache))
                                {
                                    fileStream = null;
                                }
                                else
                                {
                                    lastCache  = key;
                                    fileStream = this.fileStream;
                                }
                                break;

                            default: fileStream = this.fileStream; break;
                            }
                            if (fileStream != null)
                            {
                                if (value.Type == LogType.Flush)
                                {
                                    fileStream.Flush();
                                }
                                else
                                {
                                    string log = @"
" + Date.NowTime.Now.toString() + " : " + value.ToString() + @"
";
#if XAMARIN
                                    Trace.Console(log);
                                    if (fileStream.WriteNotEmpty(log) != -1 && (value.Type & LogType.Flush) != 0)
                                    {
                                        fileStream.Flush();
                                    }
#else
                                    if (fileStream.WriteNotEmpty(log) >= MaxSize && MaxSize > 0)
                                    {
                                        moveBak();
                                    }
                                    else if ((value.Type & LogType.Flush) != 0)
                                    {
                                        fileStream.Flush();
                                    }
#endif
                                }
                            }
                            pulseWait(value);
                        }
                        goto END;
                    }
                    catch
                    {
                        pulseWait(value);
                        CatchCount.Add(CatchCount.Type.Log_Output);
                    }
                }while (true);
END:
                debugs.SetHeaderNextNull();
            }while (true);
        }