/// <summary>设置返回值 /// </summary> private void HandleReceivedPack(ReceivedPackage package) { try { //返回为Strem,需要逐步进行解析 _resp.Header = new FastDFSHeader(package.Length, package.Command, package.Status); if (!_context.IsOutputStream) { _resp.LoadContent(Configuration, package.Body); } _context = null; _tcs.SetResult(_resp); //释放 ReferenceCountUtil.SafeRelease(package); } catch (Exception ex) { Logger.LogError("接收返回信息出错! {0}", ex); throw; } }
private async void DoReceive() { while (!_cts.IsCancellationRequested && IsConnected) { var package = await _client.ReceiveAsync(); if (package == null) { break; } if (package.IsOutputStream) { if (!_hasWriteFile) { _fileStream = new FileStream(package.OutputFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); _hasWriteFile = true; } //写入文件 await _fileStream.WriteAsync(package.Body, 0, package.Body.Length); //刷新到磁盘 if (!package.IsComplete) { continue; } await _fileStream.FlushAsync(); } //返回为Strem,需要逐步进行解析 _resp.Header = new FastDFSHeader(package.Length, package.Command, package.Status); if (!_context.IsOutputStream) { _resp.LoadContent(Configuration, package.Body); } Reset(); _tcs.SetResult(_resp); } }