/// <summary> /// 启动HTTP服务 /// </summary> /// <param name="registerServer">HTTP 注册管理服务</param> /// <param name="domains">域名信息集合</param> /// <param name="onStop">停止服务处理</param> /// <returns>是否启动成功</returns> public override bool Start(HttpRegister.Server registerServer, HttpRegister.Domain[] domains, Action onStop) { string path = AutoCSer.IO.File.FileNameToLower((this.path.fileNameToLower() ?? LoadCheckPath).pathSuffix()); if (Directory.Exists(path) && Interlocked.CompareExchange(ref isStart, 1, 0) == 0) { pathIdentity = PathCacheWatcher.Add(path); WorkPath = path; RegisterServer = registerServer; this.domains = domains; this.onStop += onStop; if (Http.SocketBase.Config.IsResponseCacheControl) { int clientCacheSeconds = this.clientCacheSeconds; if (clientCacheSeconds == Http.Response.StaticFileCacheControlSeconds) { cacheControl = Http.Response.StaticFileCacheControl; } else if (clientCacheSeconds == 0) { cacheControl = Http.Response.ZeroAgeBytes; } else { cacheControl = ("public, max-age=" + clientCacheSeconds.toString()).getBytes(); } } createErrorResponse(); return(true); } return(false); }
protected new bool dispose() { if (base.dispose()) { if (WorkPath != null) { PathCacheWatcher.Free(WorkPath); } return(true); } return(false); }
/// <summary> /// 添加监视路径 /// </summary> /// <param name="path"></param> /// <returns>路径标识</returns> internal static int Add(string path) { PathCacheWatcher cache; Monitor.Enter(cacheLock); if (caches.TryGetValue(path, out cache)) { ++cache.count; Monitor.Exit(cacheLock); } else { try { caches.Add(path, cache = new PathCacheWatcher(path)); } finally { Monitor.Exit(cacheLock); } } return(cache.identity); }