private void WorkTaskComplete(Task task, RequestData requestData, OwinContext owinContext, bool keep) { if (task.IsCompleted) { ResponseEnd(requestData, owinContext, keep); return; } if (owinContext != null && owinContext.ResponseBody != null) { try { ((OwinResponseStream)owinContext.ResponseBody).Dispose(); } catch { //ignore } } _owinCallCompleteCallback(requestData, false);//关闭Tcp }
/// <summary> /// 读取完毕 判断是否Connection 保持着 如果是不关闭tcp链接 /// </summary> /// <param name="requestData"></param> /// <param name="owinContext"></param> /// <param name="iskeep"></param> private void ResponseEnd(RequestData requestData, OwinContext owinContext, bool iskeep) { bool flag = false; if (owinContext != null && owinContext.ResponseBody != null) { try { OwinResponseStream owinResponseStream = (OwinResponseStream)owinContext.ResponseBody; owinResponseStream.ResponseEnd(); flag = !owinResponseStream.ConnectionClosed; owinResponseStream.Dispose(); } catch { //ignore } } bool flag3 = iskeep && flag; _owinCallCompleteCallback(requestData, flag3); }