Esempio n. 1
0
 internal void Set(webCall.call webCall, socketBase socket, domainServer domainServer, long socketIdentity, requestHeader request, call call)
 {
     this.webCall        = webCall;
     this.socket         = socket;
     this.domainServer   = domainServer;
     this.SocketIdentity = socketIdentity;
     this.request        = request;
     this.call           = call;
 }
Esempio n. 2
0
 private void push()
 {
     webCall      = null;
     socket       = null;
     domainServer = null;
     request      = null;
     form         = null;
     call         = null;
     typePool <loader> .PushNotNull(this);
 }
Esempio n. 3
0
 /// <summary>
 /// WebSocket调用加载
 /// </summary>
 /// <param name="domainServer">域名服务</param>
 /// <param name="socket">HTTP套接字接口设置</param>
 /// <param name="socketIdentity">套接字操作编号</param>
 internal void Load(domainServer domainServer, socketBase socket, long socketIdentity)
 {
     Socket = socket;
     try
     {
         if (!socket.ResponseWebSocket101(ref socketIdentity, this))
         {
             return;
         }
         DomainServer   = domainServer;
         SocketIdentity = socketIdentity;
         requestHeader  = socket.RequestHeader;
         if (loadSocket())
         {
             return;
         }
     }
     catch (Exception error)
     {
         log.Error.Add(error, null, false);
     }
     socket.ResponseError(socketIdentity, net.tcp.http.response.state.ServerError500);
 }
Esempio n. 4
0
 internal void SetJsContentType(domainServer domainServer)
 {
     ContentType = domainServer.JsContentType;
 }
Esempio n. 5
0
 /// <summary>
 /// 设置js内容类型
 /// </summary>
 /// <param name="domainServer">域名服务</param>
 internal void SetJsContentType(domainServer domainServer)
 {
     ContentType = domainServer.JsContentType;
 }
Esempio n. 6
0
 /// <summary>
 /// 删除域名服务信息
 /// </summary>
 /// <param name="domain"></param>
 /// <param name="server">域名服务信息</param>
 /// <returns></returns>
 public domainSearcher Remove(byte[] domain, out domainSearcher removeDomains, out domainServer server)
 {
     byte[][] domains = this.domains;
     domainServer[] servers = Servers;
     pointer data = this.data;
     if (data.Data != null && domain.Length != 0)
     {
         int index = new searcher(data).Search(domain);
         if (index >= 0)
         {
             domainSearcher searcher = Default;
             if (domains.Length != 1)
             {
                 int length = domains.Length - 1;
                 byte[][] newDomains = new byte[length][];
                 domainServer[] newServers = new domainServer[length];
                 Array.Copy(domains, 0, newDomains, 0, index);
                 Array.Copy(servers, 0, newServers, 0, index);
                 Array.Copy(domains, index + 1, newDomains, index, length - index);
                 Array.Copy(servers, index + 1, newServers, index, length - index);
                 searcher = new domainSearcher(newDomains, newServers);
             }
             server = servers[index];
             removeDomains = this;
             return searcher;
         }
     }
     server = null;
     removeDomains = null;
     return this;
 }
Esempio n. 7
0
 /// <summary>
 /// 添加域名服务信息
 /// </summary>
 /// <param name="domain"></param>
 /// <param name="server"></param>
 /// <returns></returns>
 public domainSearcher Add(byte[] domain, domainServer server, out domainSearcher removeDomains)
 {
     byte[][] domains = this.domains;
     domainServer[] servers = Servers;
     pointer data = this.data;
     if (domain.Length != 0 && ((data.Data == null || new searcher(data).Search(domain) < 0)))
     {
         byte[] reverseDomain = new byte[domain.Length];
         fixed (byte* domainFixed = domain, reverseDomainFixed = reverseDomain)
         {
             for (byte* start = domainFixed, end = domainFixed + domain.Length, write = reverseDomainFixed + domain.Length; start != end; *--write = *start++) ;
         }
         domainSearcher searcher = new domainSearcher(domains.getAdd(reverseDomain), servers.getAdd(server));
         removeDomains = this;
         return searcher;
     }
     removeDomains = null;
     return this;
 }
Esempio n. 8
0
 /// <summary>
 /// 域名搜索
 /// </summary>
 /// <param name="domains">域名信息集合</param>
 /// <param name="servers">域名服务信息集合</param>
 private domainSearcher(byte[][] domains, domainServer[] servers)
 {
     this.domains = domains;
     Servers = servers;
     data = fastCSharp.stateSearcher.byteArray.Create(domains);
 }
Esempio n. 9
0
 private unsafe startState start(string assemblyPath, string serverType, domain[] domains, bool isShareAssembly)
 {
     if (isDisposed != 0) return startState.Disposed;
     if (domains.length() == 0) return startState.DomainError;
     FileInfo assemblyFile = new FileInfo(assemblyPath);
     if (!File.Exists(assemblyPath))
     {
         log.Error.Add("未找到程序集 " + assemblyPath, false, false);
         return startState.NotFoundAssembly;
     }
     int domainCount = 0;
     startState state = startState.Unknown;
     domainServer server = new domainServer { AssemblyPath = assemblyPath, ServerType = serverType, Servers = this, IsShareAssembly = isShareAssembly };
     foreach (domain domain in domains)
     {
         if ((state = checkDomain(ref domains[domainCount], server)) != startState.Success) break;
         ++domainCount;
     }
     try
     {
         if (state == startState.Success)
         {
             state = startState.StartError;
             Assembly assembly = null;
             DirectoryInfo directory = assemblyFile.Directory;
             keyValue<domain, int>[] domainFlags = domains.getArray(value => new keyValue<domain, int>(value, 0));
             hashString pathKey = assemblyPath;
             Monitor.Enter(assemblyLock);
             try
             {
                 if (!isShareAssembly || !assemblyCache.TryGetValue(pathKey, out assembly))
                 {
                     string serverPath = this.serverPath + ((ulong)CoreLibrary.PubPlus.StartTime.Ticks).toHex16() + ((ulong)CoreLibrary.PubPlus.Identity).toHex16() + fastCSharp.directory.DirectorySeparator;
                     Directory.CreateDirectory(serverPath);
                     foreach (FileInfo file in directory.GetFiles()) file.CopyTo(serverPath + file.Name);
                     assembly = Assembly.LoadFrom(serverPath + assemblyFile.Name);
                     if (isShareAssembly) assemblyCache.Add(pathKey, assembly);
                 }
             }
             finally { Monitor.Exit(assemblyLock); }
             server.Server = (http.domainServer)Activator.CreateInstance(assembly.GetType(serverType));
             DirectoryInfo loadDirectory = directory;
             do
             {
                 string loadPath = loadDirectory.Name.toLower();
                 if (loadPath == "release" || loadPath == "bin" || loadPath == "debug")
                 {
                     loadDirectory = loadDirectory.Parent;
                 }
                 else break;
             }
             while (loadDirectory != null);
             server.Server.LoadCheckPath = (loadDirectory ?? directory).FullName;
             if (server.Server.Start(domains, server.RemoveFileWatcher))
             {
                 fileWatcher.Add(directory.FullName);
                 server.FileWatcherPath = directory.FullName;
                 if ((state = start(domains)) == startState.Success)
                 {
                     server.DomainCount = domains.Length;
                     server.Domains = domainFlags;
                     server.IsStart = true;
                     log.Default.Add(@"domain success
     " + domains.joinString(@"
     ", domain => domain.Host.Host + ":" + domain.Host.Port.toString() + "[" + domain.Domain.deSerialize() + "]"), false, false);
                     return startState.Success;
                 }
             }
         }
     }
     catch (Exception error)
     {
         log.Error.Add(error, null, false);
     }
     foreach (domain domain in domains)
     {
         if (domainCount-- == 0) break;
         removeDomain(domain);
     }
     server.Dispose();
     return state;
 }
Esempio n. 10
0
 /// <summary>
 /// 域名状态检测
 /// </summary>
 /// <param name="domain">域名信息</param>
 /// <param name="server">域名服务</param>
 /// <returns>域名状态</returns>
 private startState checkDomain(ref domain domain, domainServer server)
 {
     byte[] domainData = domain.Domain;
     if (domain.Host.Port == 0) domain.Host.Port = domain.CertificateFileName == null ? 80 : 443;
     if (domainData == null)
     {
         string domainString = domain.Host.Host;
         if (domainString.length() == 0) return servers.startState.DomainError;
         if (domain.Host.Port != (domain.CertificateFileName == null ? 80 : 443))
         {
             domainString += ":" + domain.Host.Port.toString();
         }
         domain.Domain = domainData = domainString.getBytes();
         fastCSharp.log.Default.Add(domainString + " 缺少指定域名", false, false);
     }
     else if (domainData.Length == 0) return servers.startState.DomainError;
     else if (domain.Host.Port != (domain.CertificateFileName == null ? 80 : 443) && domainData.indexOf((byte)':') == -1)
     {
         domain.Domain = domainData = (domainData.deSerialize() + ":" + domain.Host.Port.toString()).getBytes();
     }
     if (!domain.Host.HostToIpAddress()) return servers.startState.HostError;
     if (domain.CertificateFileName != null && !File.Exists(domain.CertificateFileName))
     {
         fastCSharp.log.Error.Add("没有找到安全证书文件 " + domain.CertificateFileName, false, false);
         return servers.startState.CertificateError;
     }
     domainData.toLower();
     domainSearcher removeDomains = null;
     Monitor.Enter(domainLock);
     try
     {
         domains = domains.Add(domainData, server, out removeDomains);
     }
     finally
     {
         Monitor.Exit(domainLock);
         if (removeDomains != null) removeDomains.Dispose();
     }
     return removeDomains == null ? startState.DomainExists : servers.startState.Success;
 }