Exemple #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();
            }
        }
Exemple #2
0
        private void Close()
        {
            if (_actionIndex > 0)
            {
                ActionStoreManage.Remove(_actionIndex, new Action(ReadStop));
            }
            _actionIndex = 0;
            _closeing    = true;
            RecoverMemoryInfo();
            ShutdownHandle shutdownHandle = new ShutdownHandle();

            shutdownHandle.Init(_clientHandle.Loop);
            shutdownHandle.ShutDown(_clientHandle, new Action <int, object>(CloseCallBack), null);
        }
Exemple #3
0
        private void ReadForPost(object state)
        {
            ReadState readState = (ReadState)state;

            try
            {
                _actionIndex = ActionStoreManage.Add(new Action(ReadStop));
                _clientHandle.Read(new Func <UvStreamHandle, int, object, LibUv.BufferStruct>(AllocCallback),
                                   new Action <UvStreamHandle, int, Exception, object>(ReadCallback), readState);
            }
            catch (Exception error)
            {
                ActionStoreManage.Remove(_actionIndex, new Action(ReadStop));
                _actionIndex = 0;
                readState.Callback(this, null, -1, error, readState.OtheState);
            }
        }