Esempio n. 1
0
 /// <summary>
 /// TCP 服务端套接字
 /// </summary>
 /// <param name="binaryDeSerializeConfig">二进制反序列化配置参数</param>
 /// <param name="callQueueArray">TCP 服务器端同步调用队列数组</param>
 /// <param name="callQueue">TCP 服务器端同步调用队列</param>
 /// <param name="callQueueLink">TCP 服务器端同步调用队列(低优先级)</param>
 /// <param name="verifyMethodCount">验证函数调用次数</param>
 internal ServerSocket(AutoCSer.BinarySerialize.DeSerializeConfig binaryDeSerializeConfig, KeyValue <ServerCallCanDisposableQueue, ServerCallCanDisposableQueue.LowPriorityLink>[] callQueueArray, ServerCallCanDisposableQueue callQueue, ServerCallCanDisposableQueue.LowPriorityLink callQueueLink, byte verifyMethodCount)
 {
     this.binaryDeSerializeConfig = binaryDeSerializeConfig;
     CallQueueArray         = callQueueArray;
     CallQueue              = callQueue;
     CallQueueLink          = callQueueLink;
     this.verifyMethodCount = verifyMethodCount;
 }
Esempio n. 2
0
        /// <summary>
        /// TCP 服务客户端
        /// </summary>
        /// <param name="attribute">TCP服务调用配置</param>
        /// <param name="verify">获取客户端请求线程调用类型</param>
        /// <param name="extendCommandBits">扩展服务命令二进制位数</param>
        /// <param name="log">日志接口</param>
        /// <param name="callQueueCount">独占的 TCP 服务器端同步调用队列数量</param>
        /// <param name="isCallQueueLink">是否提供独占的 TCP 服务器端同步调用队列(低优先级)</param>
        /// <param name="isSynchronousVerifyMethod">验证函数是否同步调用</param>
        internal ServerBase(ServerBaseAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, byte extendCommandBits, ILog log, int callQueueCount, bool isCallQueueLink, bool isSynchronousVerifyMethod)
            : base(attribute, attribute.GetReceiveBufferSize, attribute.GetSendBufferSize, attribute.GetServerSendBufferMaxSize, log)
        {
#if !NOJIT
            if (extendCommandBits == 0)
            {
                extendServerSet = ExtendServerSet.Null;
            }
            else if (extendCommandBits < 9 || extendCommandBits > 16)
            {
                throw new IndexOutOfRangeException("扩展服务命令二进制位数 " + extendCommandBits.toString() + " 超出范围 9-16");
            }
            else
            {
                extendServerSet = new ExtendServerSet(this, extendCommandBits);
            }
#endif
            this.verify = verify;
            if (callQueueCount > 0)
            {
                if (callQueueCount == 1)
                {
                    CallQueue = new ServerCallCanDisposableQueue(true, Log);
                    if (isCallQueueLink)
                    {
                        CallQueueLink = CallQueue.CreateLink();
                    }
                }
                else
                {
                    CallQueueArray = new KeyValue <ServerCallCanDisposableQueue, Threading.TaskQueueThread <ServerCallBase> .LowPriorityLink> [Math.Min(callQueueCount, 256)];
                    if (isCallQueueLink)
                    {
                        for (int index = 0; index != CallQueueArray.Length; ++index)
                        {
                            ServerCallCanDisposableQueue callQueue = new ServerCallCanDisposableQueue(true, Log);
                            CallQueueArray[index].Set(callQueue, callQueue.CreateLink());
                        }
                        CallQueueLink = CallQueueArray[0].Value;
                    }
                    else
                    {
                        for (int index = 0; index != CallQueueArray.Length; ++index)
                        {
                            CallQueueArray[index].Key = new ServerCallCanDisposableQueue(true, Log);
                        }
                    }
                    CallQueue = CallQueueArray[0].Key;
                }
            }
            ServerAttribute.Set(attribute);
            Port      = attribute.Port;
            IpAddress = HostPort.HostToIPAddress(attribute.Host, Log);
            int binaryDeSerializeMaxArraySize = attribute.GetBinaryDeSerializeMaxArraySize;
            BinaryDeSerializeConfig = AutoCSer.Net.TcpOpenServer.ServerAttribute.GetBinaryDeSerializeConfig(binaryDeSerializeMaxArraySize <= 0 ? AutoCSer.BinaryDeSerializer.DefaultConfig.MaxArraySize : binaryDeSerializeMaxArraySize);
            VerifyMethodCount       = isSynchronousVerifyMethod ? Server.DefaultVerifyMethodCount : (byte)(Server.DefaultVerifyMethodCount + 1);
        }
Esempio n. 3
0
 /// <summary>
 /// TCP 服务客户端
 /// </summary>
 /// <param name="attribute">TCP服务调用配置</param>
 /// <param name="verify">获取客户端请求线程调用类型</param>
 /// <param name="log">日志接口</param>
 /// <param name="isCallQueue">是否提供独占的 TCP 服务器端同步调用队列</param>
 internal ServerBase(attributeType attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, bool isCallQueue)
     : base(attribute, attribute.GetReceiveBufferSize, attribute.GetSendBufferSize, attribute.GetServerSendBufferMaxSize, log)
 {
     this.verify = verify;
     if (isCallQueue)
     {
         CallQueue = new ServerCallCanDisposableQueue();
     }
     Port      = attribute.Port;
     IpAddress = HostPort.HostToIPAddress(attribute.Host, Log);
 }
Esempio n. 4
0
        /// <summary>
        /// TCP 服务客户端
        /// </summary>
        /// <param name="attribute">TCP服务调用配置</param>
        /// <param name="verify">获取客户端请求线程调用类型</param>
        /// <param name="log">日志接口</param>
        /// <param name="isCallQueue">是否提供独占的 TCP 服务器端同步调用队列</param>
        internal ServerBase(attributeType attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, bool isCallQueue)
            : base(attribute, attribute.GetReceiveBufferSize, attribute.GetSendBufferSize, attribute.GetServerSendBufferMaxSize, log)
        {
            this.verify = verify;
            if (isCallQueue)
            {
                CallQueue = new ServerCallCanDisposableQueue();
            }
            Port      = attribute.Port;
            IpAddress = HostPort.HostToIPAddress(attribute.Host, Log);
            int binaryDeSerializeMaxArraySize = attribute.GetBinaryDeSerializeMaxArraySize;

            BinaryDeSerializeConfig = AutoCSer.Net.TcpOpenServer.ServerAttribute.GetBinaryDeSerializeConfig(binaryDeSerializeMaxArraySize <= 0 ? AutoCSer.BinarySerialize.DeSerializer.DefaultConfig.MaxArraySize : binaryDeSerializeMaxArraySize);
        }
Esempio n. 5
0
 /// <summary>
 /// 停止服务
 /// </summary>
 public override void Dispose()
 {
     if (Interlocked.CompareExchange(ref IsDisposed, 1, 0) == 0 && isListen != 0)
     {
         isListen = 0;
         if (Log.IsAnyType(AutoCSer.Log.LogType.Info))
         {
             Log.Add(AutoCSer.Log.LogType.Info, "停止服务 " + ServerName + " " + IpAddress.ToString() + "[" + Attribute.Host + "]:" + Port.toString());
         }
         AutoCSer.DomainUnload.Unloader.Remove(this, DomainUnload.Type.TcpCommandBaseDispose, false);
         StopListen();
         if (CallQueue != null)
         {
             CallQueue.Dispose();
             CallQueue = null;
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// TCP 服务客户端
        /// </summary>
        /// <param name="attribute">TCP服务调用配置</param>
        /// <param name="verify">获取客户端请求线程调用类型</param>
        /// <param name="log">日志接口</param>
        /// <param name="callQueueCount">独占的 TCP 服务器端同步调用队列数量</param>
        /// <param name="isCallQueueLink">是否提供独占的 TCP 服务器端同步调用队列(低优先级)</param>
        /// <param name="isSynchronousVerifyMethod">验证函数是否同步调用</param>
        internal ServerBase(ServerBaseAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, int callQueueCount, bool isCallQueueLink, bool isSynchronousVerifyMethod)
            : base(attribute, attribute.GetReceiveBufferSize, attribute.GetSendBufferSize, attribute.GetServerSendBufferMaxSize, log)
        {
            this.verify = verify;
            if (callQueueCount > 0)
            {
                if (callQueueCount == 1)
                {
                    CallQueue = new ServerCallCanDisposableQueue(true, Log);
                    if (isCallQueueLink)
                    {
                        CallQueueLink = CallQueue.CreateLink();
                    }
                }
                else
                {
                    CallQueueArray = new KeyValue <ServerCallCanDisposableQueue, Threading.QueueTaskLinkThread <ServerCallBase> .LowPriorityLink> [Math.Min(callQueueCount, 256)];
                    if (isCallQueueLink)
                    {
                        for (int index = 0; index != CallQueueArray.Length; ++index)
                        {
                            ServerCallCanDisposableQueue callQueue = new ServerCallCanDisposableQueue(true, Log);
                            CallQueueArray[index].Set(callQueue, callQueue.CreateLink());
                        }
                        CallQueueLink = CallQueueArray[0].Value;
                    }
                    else
                    {
                        for (int index = 0; index != CallQueueArray.Length; ++index)
                        {
                            CallQueueArray[index].Key = new ServerCallCanDisposableQueue(true, Log);
                        }
                    }
                    CallQueue = CallQueueArray[0].Key;
                }
            }
            ServerAttribute.Set(attribute);
            Port      = attribute.Port;
            IpAddress = HostPort.HostToIPAddress(attribute.Host, Log);
            int binaryDeSerializeMaxArraySize = attribute.GetBinaryDeSerializeMaxArraySize;

            BinaryDeSerializeConfig = AutoCSer.Net.TcpOpenServer.ServerAttribute.GetBinaryDeSerializeConfig(binaryDeSerializeMaxArraySize <= 0 ? AutoCSer.BinarySerialize.DeSerializer.DefaultConfig.MaxArraySize : binaryDeSerializeMaxArraySize);
            VerifyMethodCount       = isSynchronousVerifyMethod ? Server.DefaultVerifyMethodCount : (byte)(Server.DefaultVerifyMethodCount + 1);
        }
Esempio n. 7
0
 /// <summary>
 /// TCP 服务端套接字
 /// </summary>
 /// <param name="binaryDeSerializeConfig">二进制反序列化配置参数</param>
 /// <param name="callQueue">TCP 服务器端同步调用队列</param>
 /// <param name="verifyMethodCount">验证函数调用次数</param>
 internal ServerSocket(AutoCSer.BinarySerialize.DeSerializeConfig binaryDeSerializeConfig, ServerCallCanDisposableQueue callQueue, byte verifyMethodCount)
 {
     this.binaryDeSerializeConfig = binaryDeSerializeConfig;
     CallQueue = callQueue;
     this.verifyMethodCount = verifyMethodCount;
 }