Beispiel #1
0
 internal void CancelReceiveVerifyCommandTimeout(SocketTimeoutLink socket)
 {
     SocketTimeoutLink.TimerLink receiveVerifyCommandTimeout = this.ReceiveVerifyCommandTimeout;
     if (receiveVerifyCommandTimeout != null)
     {
         receiveVerifyCommandTimeout.Cancel(socket);
     }
 }
Beispiel #2
0
        internal void PushTimeout(HttpClient client, Socket socket)
        {
            SocketTimeoutLink socketTimeout = this.socketTimeout;

            if (socketTimeout != null)
            {
                socketTimeout.Push(client, socket);
            }
        }
Beispiel #3
0
        internal void CancelTimeout(HttpClient client)
        {
            SocketTimeoutLink socketTimeout = this.socketTimeout;

            if (socketTimeout != null)
            {
                socketTimeout.Cancel(client);
            }
        }
Beispiel #4
0
 internal bool PushReceiveVerifyCommandTimeout(SocketTimeoutLink serverSocket, Socket socket)
 {
     SocketTimeoutLink.TimerLink receiveVerifyCommandTimeout = this.ReceiveVerifyCommandTimeout;
     if (receiveVerifyCommandTimeout != null)
     {
         receiveVerifyCommandTimeout.Push(serverSocket, socket);
         return(true);
     }
     return(false);
 }
Beispiel #5
0
 /// <summary>
 /// 获取客户端请求
 /// </summary>
 internal void GetSocket()
 {
     ReceiveVerifyCommandTimeout = new SocketTimeoutLink(ServerAttribute.ReceiveVerifyCommandSeconds > 0 ? ServerAttribute.ReceiveVerifyCommandSeconds : TcpInternalServer.ServerAttribute.DefaultReceiveVerifyCommandSeconds);
     try
     {
         if (verify == null)
         {
             getSocket();
         }
         else
         {
             getSocketVerify();
         }
     }
     finally { SocketTimeoutLink.Free(ref ReceiveVerifyCommandTimeout); }
 }
Beispiel #6
0
 /// <summary>
 /// HTML标题获取客户端任务池
 /// </summary>
 /// <param name="maxClientCount">最大实例数量</param>
 /// <param name="timeoutSeconds">套接字操作超时时间</param>
 /// <param name="bufferSize">收发数据缓冲区字节数</param>
 /// <param name="maxSearchSize">最大搜索字节数</param>
 /// <param name="isValidateCertificate">是否验证安全证书</param>
 /// <param name="log">日志处理</param>
 public HttpTask(int maxClientCount = 1, int timeoutSeconds = 15, AutoCSer.Memory.BufferSize bufferSize = AutoCSer.Memory.BufferSize.Kilobyte4, int maxSearchSize = 0, bool isValidateCertificate = false, AutoCSer.ILog log = null)
 {
     if (bufferSize < MinBufferSize)
     {
         bufferSize = MinBufferSize;
     }
     else if (bufferSize > AutoCSer.Memory.BufferSize.Kilobyte32)
     {
         bufferSize = AutoCSer.Memory.BufferSize.Kilobyte32;
     }
     BufferSize            = (int)bufferSize;
     MaxSearchSize         = Math.Min(BufferSize - sizeof(int), maxSearchSize);
     IsValidateCertificate = isValidateCertificate;
     this.Log      = log ?? AutoCSer.LogHelper.Default;
     BufferPool    = AutoCSer.SubBuffer.Pool.GetPool(bufferSize);
     uris          = new Uri.Queue(new Uri());
     socketTimeout = new SocketTimeoutLink(Math.Max(timeoutSeconds, 15));
     clients       = new HttpClient[maxClientCount <= 0 ? 1 : maxClientCount];
 }
Beispiel #7
0
 /// <summary>
 /// 获取客户端请求
 /// </summary>
 internal void GetSocket()
 {
     //ThreadPriority priority = Thread.CurrentThread.Priority;
     ReceiveVerifyCommandTimeout = new SocketTimeoutLink(ServerAttribute.ReceiveVerifyCommandSeconds > 0 ? ServerAttribute.ReceiveVerifyCommandSeconds : TcpOpenServer.ServerAttribute.DefaultReceiveVerifyCommandSeconds);
     try
     {
         socketHandle.Set(0);
         AutoCSer.Threading.ThreadPool.TinyBackground.FastStart(this, AutoCSer.Threading.ThreadTaskType.TcpOpenServerOnSocket);
         //Thread.CurrentThread.Priority = ThreadPriority.Highest;
         if (verify == null)
         {
             getSocket();
         }
         else
         {
             getSocketVerify();
         }
         //Thread.CurrentThread.Priority = priority;
         socketHandle.Set();
     }
     finally { SocketTimeoutLink.Free(ref ReceiveVerifyCommandTimeout); }
 }
Beispiel #8
0
        /// <summary>
        /// 释放资源
        /// </summary>
        public void Dispose()
        {
            if (isDisposed == 0)
            {
                int clientIndex = 0;
                Uri uri         = null;
                clientLock.EnterYield();
                if (isDisposed == 0)
                {
                    isDisposed       = 1;
                    clientIndex      = this.clientIndex;
                    this.clientIndex = 0;
                    uri = uris.GetClear();
                }
                clientLock.Exit();

                if (clientIndex != 0)
                {
                    foreach (HttpClient client in clients)
                    {
                        client.Free();
                        if (--clientIndex == 0)
                        {
                            break;
                        }
                    }
                }
                Array.Clear(clients, 0, clients.Length);
                if (uri != null)
                {
                    uri.CancelQueue(Log);
                }

                SocketTimeoutLink.Free(ref socketTimeout);
            }
        }