Пример #1
0
 /// <summary>
 /// 停止服务监听
 /// </summary>
 public void StopListen()
 {
     pub.Dispose(ref this.socket);
     fastCSharp.net.tcp.tcpRegister.client tcpRegisterClient = Interlocked.Exchange(ref this.tcpRegisterClient, null);
     if (tcpRegisterClient != null)
     {
         tcpRegisterClient.RemoveRegister(attribute);
     }
 }
Пример #2
0
        /// <summary>
        /// TCP调用服务端
        /// </summary>
        /// <param name="attribute">配置信息</param>
        protected server(fastCSharp.code.cSharp.tcpServer attribute)
        {
            if (attribute == null)
            {
                log.Error.Throw(log.exceptionType.Null);
            }
            if (attribute.TcpRegisterName != null)
            {
                tcpRegisterClient = fastCSharp.net.tcp.tcpRegister.client.Get(attribute.TcpRegisterName);
                if (tcpRegisterClient == null)
                {
                    log.Error.Throw("TCP注册服务 " + attribute.TcpRegisterName + " 链接失败", null, false);
                }
                if (attribute.RegisterHost == null)
                {
                    attribute.RegisterHost = attribute.Host;
                }
                if (attribute.RegisterPort == 0)
                {
                    attribute.RegisterPort = attribute.Port;
                }
                fastCSharp.net.tcp.tcpRegister.registerState state = tcpRegisterClient.Register(attribute);
                if (state != fastCSharp.net.tcp.tcpRegister.registerState.Success)
                {
                    log.Error.Throw("TCP服务注册 " + attribute.ServiceName + " 失败 " + state.ToString(), null, false);
                }
                if (attribute.Port == 0)
                {
                    attribute.Port = attribute.RegisterPort;
                }
                log.Default.Add(attribute.ServiceName + " 注册 " + attribute.Host + ":" + attribute.Port.toString() + " => " + attribute.RegisterHost + ":" + attribute.RegisterPort.toString(), new System.Diagnostics.StackFrame(), false);
            }
            if (!attribute.IsServer)
            {
                log.Default.Add("配置未指明的TCP服务端 " + attribute.ServiceName, null, false);
            }
            this.attribute = attribute;
            if ((maxClientCount = attribute.MaxClientCount) <= 0)
            {
                maxClientCount = int.MaxValue;
            }
#if MONO
            //if (attribute.AcceptQueueSize > 30) attribute.AcceptQueueSize = 30;
            //else if (attribute.AcceptQueueSize < 4) attribute.AcceptQueueSize = 4;
#endif
        }
Пример #3
0
 /// <summary>
 /// TCP调用服务端
 /// </summary>
 /// <param name="attribute">配置信息</param>
 protected server(fastCSharp.code.cSharp.tcpServer attribute)
 {
     if (attribute == null) log.Error.Throw(log.exceptionType.Null);
     if (attribute.TcpRegisterName != null)
     {
         tcpRegisterClient = fastCSharp.net.tcp.tcpRegister.client.Get(attribute.TcpRegisterName);
         if (tcpRegisterClient == null) log.Error.Throw("TCP注册服务 " + attribute.TcpRegisterName + " 链接失败", true, false);
         fastCSharp.net.tcp.tcpRegister.registerState state = tcpRegisterClient.Register(attribute);
         if (state != fastCSharp.net.tcp.tcpRegister.registerState.Success) log.Error.Throw("TCP服务注册 " + attribute.ServiceName + " 失败 " + state.ToString(), true, false);
         log.Default.Add(attribute.ServiceName + " 注册 " + attribute.Host + ":" + attribute.Port.toString(), false, false);
     }
     if (!attribute.IsServer) log.Default.Add("配置未指明的TCP服务端 " + attribute.ServiceName, true, false);
     this.attribute = attribute;
 }
Пример #4
0
 /// <summary>
 /// 停止服务
 /// </summary>
 public virtual void Dispose()
 {
     if (Interlocked.CompareExchange(ref isStart, 0, 1) == 1)
     {
         log.Default.Add("停止服务 " + attribute.ServiceName + "[" + attribute.Host + ":" + attribute.Port.toString() + "]", true, false);
         fastCSharp.domainUnload.Remove(Dispose, false);
         if (tcpRegisterClient != null)
         {
             tcpRegisterClient.RemoveRegister(attribute);
             tcpRegisterClient = null;
         }
         pub.Dispose(ref this.socket);
         Socket[] sockets = null;
         interlocked.NoCheckCompareSetSleep0(ref newClientLock);
         if (newClients == null || newClientCount == 0) newClientLock = 0;
         else
         {
             try
             {
                 Array.Copy(newClients, sockets = new Socket[newClientCount], newClientCount);
                 Array.Clear(newClients, 0, newClientCount);
                 newClientCount = 0;
             }
             finally { newClientLock = 0; }
             if (sockets != null)
             {
                 foreach (Socket socket in sockets) socket.shutdown();
             }
         }
         if (OnDisposed != null) OnDisposed();
     }
 }