Exemplo n.º 1
0
        /// <summary>
        /// libuv读取成功后回调函数
        /// </summary>
        /// <param name="handle">clientHandle</param>
        /// <param name="nread">读取的长度</param>
        /// <param name="error">Exception</param>
        /// <param name="state">回调参数</param>
        private void ReadCallback(UvStreamHandle handle, int nread, Exception error, object state)
        {
            if (_actionIndex > 0)
            {
                ActionStoreManage.Remove(_actionIndex, new Action(ReadStop));
                _actionIndex = 0;
            }
            bool flag = error == null && nread > 0;
            //bool flag2 = nread == 0 || nread == -4077 || nread == -4095;
            ReadState readState = (ReadState)state;

            try
            {
                if (flag)
                {
                    readState.Callback(this, _memoryInfo.Buffer, nread, null, readState.OtheState);
                }
                else
                {
                    readState.Callback(this, null, -1, error, readState.OtheState);
                }
            }
            finally
            {
                handle.Stop();
                //AllocCallback 开辟的内存空间回收
                RecoverMemoryInfo();
            }
        }